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

[9.x] Do not let SetCacheHeaders override the eTag. #39166

Merged
merged 1 commit into from
Oct 12, 2021
Merged

[9.x] Do not let SetCacheHeaders override the eTag. #39166

merged 1 commit into from
Oct 12, 2021

Conversation

lucasmichot
Copy link
Contributor

In some cases, I want to have the possibility to set my own response eTag, based on other arguments than just the the response content.

If so, I do no want it to be overridden when using SetCacheHeaders middleware.

@taylorotwell
Copy link
Member

Can you give an example of this? I'm not following.

@inxilpro
Copy link
Contributor

I can see using this, although I would do the same for Last-Modified. Right now we don't use the SetCacheHeaders middleware because we need more control over those headers, and the middleware overrides existing headers if they're set.

For example, if I had something like this, where I wanted to set the Last-Modified and ETag headers based on a model's data:

Route::get('/pages/{page}', function(Page $page) {
  return Response::create($page->toHtml())
    ->setLastModified($page->updated_at)
    ->setEtag(md5($page->body), true);
});

The SetCacheHeaders middleware would override my custom values. So my options are to manually pick which routes to apply the middleware to, or just handle cache control headers some other way.

Updating SetCacheHeaders to only generate headers if they're missing would solve that problem. You could just add it to a middleware group or globally, and know that if you don't manually apply the headers, they'll be generated for you.

@lucasmichot
Copy link
Contributor Author

Sorry for the late reply, @inxilpro summed it up way better than I could.


This PR initially initially ensures that the eTag is not overridden if already set, but the same could also apply to the Last-Modified

@taylorotwell taylorotwell merged commit 40e6536 into laravel:master Oct 12, 2021
@lucasmichot lucasmichot deleted the feat/9.x/do-not-override-etag branch August 6, 2022 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants