Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: JS caching via Access-Control-Expose-Headers #8984

Merged
merged 1 commit into from
May 19, 2022

Conversation

lidel
Copy link
Member

@lidel lidel commented May 19, 2022

This fix safelists additional headers allowing JS running on websites to read them when IPFS resource is downloaded via Fetch API.

These headers allow for making smart caching decisions (#8720) when IPFS resources are downloaded via Service Worker or a similar middleware on the edge.

@guseggert If possible, we should include it in 0.13 (I forgot to safelist them in #8720), but if it is too late, then please reassign this to 0.14.

This fix safelists additional headers allowing JS running on websites to
read them when IPFS resource is downloaded via Fetch API.

These headers provide metadata necessary for making smart caching
decisions when IPFS resources are downloaded via Service Worker or a
similar middleware on the edge.
@lidel lidel requested a review from vasco-santos May 19, 2022 17:06
@@ -84,9 +84,12 @@ func GatewayOption(writable bool, paths ...string) ServeOption {

headers[ACEHeadersName] = cleanHeaderSet(
append([]string{
"Content-Length",
Copy link
Member Author

@lidel lidel May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also included Content-Length because it was not implicitly safelisted initially by the browsers (whatwg/fetch#622, whatwg/fetch#626) and still, the current browser behavior is not consistent.

Click to expand - Firefox 100 and Chromium 1001

Works on localhost

Start go-ipfs 0.12.2 and 0.13-rc1, then go to https://example.com/ and try to access the header from js, by typing in browser console:

$ fetch('http://127.0.0.1:8080/ipfs/bafybeib4zuumguq4cgkt7caddeukb4ysijnehvntekrtu5afmet5ujvlka/package.json').then(response => console.table(Object.fromEntries(response.headers))) 
cache-control public, max-age=29030400, immutable
content-length 4674
content-type application/json
last-modified Thu, 01 Jan 1970 00:00:01 GMT

👉 when local gateway is used, fetch is able to access content-length

Fails on ipfs.io

At the same time, JS running on https://example.com is unable to read content-length if ipfs.io is used:

$ fetch('https://ipfs.io/ipfs/bafybeib4zuumguq4cgkt7caddeukb4ysijnehvntekrtu5afmet5ujvlka/package.json').then(response => console.table(Object.fromEntries(response.headers))) 
cache-control public, max-age=29030400, immutable
content-type application/json
last-modified Thu, 01 Jan 1970 00:00:01 GMT

Manually including it on our own safelist solves the problem.

@lidel lidel marked this pull request as ready for review May 19, 2022 17:18
@lidel lidel requested a review from guseggert May 19, 2022 17:18
@guseggert
Copy link
Contributor

Not too late for 0.13, will include it

@guseggert guseggert merged commit 650bc24 into master May 19, 2022
@guseggert guseggert deleted the fix/advanced-caching-in-js branch May 19, 2022 18:11
guseggert pushed a commit that referenced this pull request Jun 8, 2022
This fix safelists additional headers allowing JS running on websites to
read them when IPFS resource is downloaded via Fetch API.

These headers provide metadata necessary for making smart caching
decisions when IPFS resources are downloaded via Service Worker or a
similar middleware on the edge.
guseggert pushed a commit that referenced this pull request Jun 8, 2022
This fix safelists additional headers allowing JS running on websites to
read them when IPFS resource is downloaded via Fetch API.

These headers provide metadata necessary for making smart caching
decisions when IPFS resources are downloaded via Service Worker or a
similar middleware on the edge.

(cherry picked from commit 650bc24)
guseggert pushed a commit that referenced this pull request Jun 8, 2022
This fix safelists additional headers allowing JS running on websites to
read them when IPFS resource is downloaded via Fetch API.

These headers provide metadata necessary for making smart caching
decisions when IPFS resources are downloaded via Service Worker or a
similar middleware on the edge.

(cherry picked from commit 650bc24)
guseggert pushed a commit that referenced this pull request Jun 8, 2022
This fix safelists additional headers allowing JS running on websites to
read them when IPFS resource is downloaded via Fetch API.

These headers provide metadata necessary for making smart caching
decisions when IPFS resources are downloaded via Service Worker or a
similar middleware on the edge.

(cherry picked from commit 650bc24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants