How do I set Expires: header when using send_data

老子叫甜甜 提交于 2019-12-03 12:20:59

I came across this syntax and I like it :-)

response.headers["Expires"] = 1.year.from_now.httpdate
conny

Apparently there seems to be no way to pass expires to send_data - instead you must set it yourself in response.headers and take care of formatting the date appropriately:

response.headers["Expires"] = CGI.rfc1123_date(Time.now + period)

Note that the max-age directive in the Cache-Control header overrides the Expires header if both are present. See RFC2616 Section 14.9.3 for more details.

jaan

The code in your question should actually work on recent Rails:

`expires_in 10.hours, :public => true`
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!