Repository navigation
Conversation
This PR adds support for dynamic headers in Rack::Files via the headers
configuration.
For example the following configuration add the header "x-dynamic" with
a random integer between 1 and 10 for each request handled by Rack::Files:
```
Rack::Files.new(".", {
"x-dynamic" => ->(request) { rand(1..10).to_s }
})
```
This feature could be used to provide different cache durations
for different files. E.g. a longer duration for files with a
contenthash and shorter duration for files without a contenthash. This
would allow solving issues like
rails/rails#55249 within Rack::Files directly.
jeremyevans
left a comment
There was a problem hiding this comment.
I'm against adding this, as I don't think the complexity is worth the benefit. I'd be OK adding a set_headers method that is passed the base headers and request, and runs headers.merge!(@headers) if @headers by default. You could then subclass Rack::Files and override the method to add the behavior you want.
|
I think this is a great suggestion. This keeps |
|
I adapted the PR to provide a public |
jeremyevans
left a comment
There was a problem hiding this comment.
Thanks for working on this!
|
This looks good to me but I have a slight concern about the name Perhaps |
I'm fine with either, so if you would prefer |
|
@codergeek121 wdyt? |
|
I'd be fine with both names as well. I think your points made sense though and I've renamed the method 👍 |
This PR adds support for dynamic headers in Rack::Files via the headers configuration.
For example the following configuration add the header "x-dynamic" with a random integer between 1 and 10 for each request handled by Rack::Files:
This feature could be used to provide different cache durations for different files. E.g. a longer duration for files with a contenthash and shorter duration for files without a contenthash. This would allow solving issues like
rails/rails#55249 within Rack::Files directly.