【问题标题】:Cache-Control header reverts to private with send_data methodCache-Control 标头使用 send_data 方法恢复为私有
【发布时间】:2015-08-19 21:47:46
【问题描述】:

我试图在 Rails 4 中使用 send_data 方法渲染图像时将 Cache-Control 标头设置为公共,但无论我做什么,Rails 都会将其更改为私有..

控制器代码:

response.headers['Cache-Control'] = 'public, max-age=31556926'
send_data data, disposition: 'inline'

在浏览器中查看时:

Cache-Control:max-age=31556926, private

我怎样才能摆脱这个私人关键字?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    我通过使用 expires_in 方法解决了这个问题,而不是手动编辑标题:

    expires_in 1.year, public: true
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。单独使用 expires_in 并没有解决它。我最终手动和通过 expires_in 设置 Cache-Control 和 Expires 标头来解决问题。奇怪

      response.headers["Expires"] = 1.year.from_now.httpdate
      response.headers["Cache-Control"] = 'public'
      expires_in 1.year, public: true
      send_file file
      

      【讨论】:

        猜你喜欢
        • 2011-06-13
        • 1970-01-01
        • 1970-01-01
        • 2015-04-13
        • 2017-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多