Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.

refactored etag logic. fixes 122 #133

Merged
merged 9 commits into from
May 21, 2021

Conversation

shagamemnon
Copy link
Contributor

The TL;DR on issue #122 : I discovered that when a Worker subrequest ...

  • Sets a strong etag before caches.default.put() (like etag: "xyc")
  • But weakens this etag to etag: W/"xyc" before serving eyeball

Then ...

  • CF cache will respond with a 304 to the Worker
  • After subrequest leaves the worker, we will honor the 304 AND apply brotili or gzip compression

src/index.ts Outdated
headers.set('CF-Cache-Status', 'HIT')
response = new Response(response.body, { headers })
response = new Response(response.body, response)
response.headers.set('cf-cache-status', 'HIT')
Copy link
Contributor

@SukkaW SukkaW Jul 6, 2020

Choose a reason for hiding this comment

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

It seems that Cloudflare Web Server or Cloudflare Cache will add cf-cache-status header itself.

I have removed the line in my own worker script, but the header still appears in the final response.

I could open a new PR removing those cf-cache-status.

Copy link
Contributor

Choose a reason for hiding this comment

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

does that header still appear if you remove that resource from cloudflare's cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I’m not sure if the cf-cache-status headers need to be set or not. If they are redundant, I still think they should be retained b/c all the tests will need to be refactored otherwise. Best to discuss this issue on a separate thread IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

does that header still appear if you remove that resource from cloudflare's cache?

Yes.

Copy link
Contributor

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

LGTM!

@shagamemnon
Copy link
Contributor Author

@ispivey need your review on this. We should also get someone on the FL team I think

@SukkaW
Copy link
Contributor

SukkaW commented Jul 29, 2020

Will the PR being continued? I have already tested it on my website and the 304 works as expected.

@EatonZ
Copy link
Contributor

EatonZ commented Aug 25, 2020

@shagamemnon Are you still working on this? There's been a general decrease in repo activity.☹ Waiting for ETag code to be polished up before I play around with it.

@SukkaW SukkaW mentioned this pull request Sep 1, 2020
@brycewray
Copy link

Went down quite a search rabbit hole before finding these ETag-related issues, but am hoping this gets resolved soon.

@afladmark
Copy link

I too have just come across this issue. It's discouraging us from going live with Workers hosting a static site which is quite image heavy. Other than this issue, we are really excited about using this as it seems to address our needs very well.

This PR has been sitting here for more than 6 months now. Any chance of it being picked up and reviewed please?

@Tugzrida
Copy link

As others have mentioned, it'd be great for this to be merged, as etags don't seem to work at the moment :(

@caass caass added this to the 0.1.2 milestone Mar 15, 2021
@EatonZ
Copy link
Contributor

EatonZ commented Apr 13, 2021

Hi @caass, any idea when 0.1.2 may be released with this?

@caass
Copy link
Contributor

caass commented Apr 14, 2021

@EatonZ no estimate yet, unfortunately :(

@kristianfreeman
Copy link
Contributor

Hey all! Would like to help get this merged this week - I'm working on getting a new version of kv-asset-handler out by Friday. Has anyone tested this PR recently or would be interested in helping me get it over the finish line? @shagamemnon it looks like there is a few conflicts that need to be resolved, would you be available to do that?

@Cherry
Copy link
Contributor

Cherry commented May 17, 2021

Hey all! Would like to help get this merged this week - I'm working on getting a new version of kv-asset-handler out by Friday. Has anyone tested this PR recently or would be interested in helping me get it over the finish line? @shagamemnon it looks like there is a few conflicts that need to be resolved, would you be available to do that?

I tested this a while ago on some of our sites and it worked really well, with ETags as well as 304s being responded with appropriately. I'm not super intimate with the ETag spec, or Cloudflare's handling of them, but from my brief testing it all appeared to work fine.

@kristianfreeman
Copy link
Contributor

@shagamemnon looks like there's still some rebase conflicts! let me know if I can help in anyway

@kristianfreeman kristianfreeman requested a review from Cherry May 21, 2021 16:57
Copy link
Contributor

@Cherry Cherry left a comment

Choose a reason for hiding this comment

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

This looks great and I'm super excited to get this merged! I left one minor comment regarding a stray console.log, but otherwise this LGTM!

@kristianfreeman kristianfreeman merged commit 8a540d4 into cloudflare:master May 21, 2021
@Tugzrida
Copy link

Sorry, I'm not familiar with the release process here, but when should 0.1.2 make it to npm?

@Cherry
Copy link
Contributor

Cherry commented May 23, 2021

Sorry, I'm not familiar with the release process here, but when should 0.1.2 make it to npm?

Hopefully this week. I'll ping some folks tomorrow. 👍

@kristianfreeman
Copy link
Contributor

hey all! working on getting the right permissions on my end to publish to NPM, apologies for the delay!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants