杂种:: DirHandler相当于客运 [英] Mongrel::DirHandler equivalent for Passenger

查看:160
本文介绍了杂种:: DirHandler相当于客运的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用杂种:: DirHandler控制静态文件的响应报头 - 我的开发机器上这个伟大工程。我的生产机器采用乘客,所以我的头都没有得到设置。我如何控制对静态文件头使用时,乘客?

从我的environment.rb片断:

 如果界定?杂种:: DirHandler
  模块杂种
    类DirHandler
      高清send_file_with_expires(req_path,请求,响应HEADER_ONLY = FALSE)        如果req_path =〜/((\\ /图片)| JavaScript的|样式表)/
          response.header ['缓存控制'] ='最大年龄= 315360000'
          response.header ['过期'] =(Time.now + 10.years).rfc2822
        其他
          response.header [的Last-Modified] = Time.now.httpdate
          response.header [过期] = 0
          #HTTP 1.0
          response.header [杂注] ='无缓存'
          #HTTP 1.1'pre-检查= 0,检查后= 0(即特定)
          response.header [缓存控制] ='无店铺,无缓存,必重新验证,最大年龄= 0,pre-检查= 0,后期检查= 0'
        结束        send_file_without_expires(req_path,请求,响应HEADER_ONLY)
      结束
      alias_method:send_file_without_expires,:由send_file
      alias_method:由send_file,:send_file_with_expires
    结束
  结束
结束


解决方案

由于您使用的乘客,我假设你在Apache,因此您的申请不通过杂种去了。如果是这样,您可以建立您的应用程序的公共目录中的的.htaccess 文件规则。

下面是关于如何做到这一点的explination。

I'm using Mongrel::DirHandler to control response headers for static files - this works great on my dev machine. My production machine uses Passenger so my headers aren't getting set. How do I control headers for static files when using Passenger?

snippet from my environment.rb:

if defined? Mongrel::DirHandler
  module Mongrel
    class DirHandler
      def send_file_with_expires(req_path, request, response, header_only=false)

        if req_path =~ /((\/images)|javascripts|stylesheets)/
          response.header['Cache-Control'] = 'max-age=315360000'
          response.header['Expires'] = (Time.now + 10.years).rfc2822
        else
          response.header["Last-Modified"] = Time.now.httpdate
          response.header["Expires"] = 0
          # HTTP 1.0
          response.header["Pragma"] = 'no-cache'
          # HTTP 1.1 ‘pre-check=0, post-check=0′ (IE specific)
          response.header["Cache-Control"] = 'no-store, no-cache, must-revalidate, max-age=0, pre-check=0, post-check=0'
        end

        send_file_without_expires(req_path, request, response, header_only)
      end
      alias_method :send_file_without_expires, :send_file
      alias_method :send_file, :send_file_with_expires
    end
  end
end

解决方案

Since you're using Passenger, I assume you're under apache, so your request isn't going through Mongrel anymore. If so, you can establish rules on the .htaccess file inside the public directory of your application.

Here's an explination on how to do it.

这篇关于杂种:: DirHandler相当于客运的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆