Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache-Control header reverts to private with send_data method

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?

like image 847
Paludis Avatar asked Jun 09 '26 03:06

Paludis


2 Answers

I solved this by using the expires_in method rather than editing the header manually:

expires_in 1.year, public: true
like image 188
Paludis Avatar answered Jun 10 '26 19:06

Paludis


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
like image 26
Mohammad Naghibi Avatar answered Jun 10 '26 18:06

Mohammad Naghibi