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

The middleware "SetCacheHeaders" doesn't work with file responses #44036

Closed
clementbirkle opened this issue Sep 7, 2022 · 3 comments
Closed

Comments

@clementbirkle
Copy link
Contributor

  • Laravel Version: 9.26.1
  • PHP Version: 8.1.8

Description:

The middleware "SetCacheHeaders" (cache.headers) doesn't work with file responses because in this case "! $response->getContent()" seems to be empty: https://github.com/laravel/framework/blob/9.x/src/Illuminate/Http/Middleware/SetCacheHeaders.php#L24

I use a simple response like that: https://laravel.com/docs/9.x/responses#file-responses

Is it normal or it is a bug?

@driesvints
Copy link
Member

I don't think it makes sense for file responses? Should those even be cached?

@clementbirkle
Copy link
Contributor Author

Yes, I think it can make sense.

In my case, I use file responses for protected files. Each request make a query to the database to retrieve the path of the file and then return the response.

Put the file in browser cache could avoid to make this call 20 times for the same file/same user.

@driesvints
Copy link
Member

Feel free to attempt a PR if you want 👍

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

No branches or pull requests

2 participants