I'm trying to set the Cache-Control header to public when rendering an image with the send_data method in Rails 4, but no matter what I do Rails changes it to private..
Controller code:
response.headers['Cache-Control'] = 'public, max-age=31556926'
send_data data, disposition: 'inline'
When viewed in a browser:
Cache-Control:max-age=31556926, private
How can I get rid of this private keyword?
I solved this by using the expires_in method rather than editing the header manually:
expires_in 1.year, public: true
I had the same problem. Using expires_in alone didn't solve it. I ended up setting Cache-Control and Expires headers both manually and via expires_in to solve the issue. Weird
response.headers["Expires"] = 1.year.from_now.httpdate
response.headers["Cache-Control"] = 'public'
expires_in 1.year, public: true
send_file file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With