Skip to content

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.

3 participants