Mongrel :: DirHandler相当于Passenger

时间:2008-10-23 17:00:39

标签: ruby-on-rails ruby apache passenger mongrel

我正在使用Mongrel :: DirHandler来控制静态文件的响应头 - 这在我的开发机器上运行良好。我的生产机器使用Passenger所以我的标题没有设置。使用Passenger时如何控制静态文件的标题?

来自环境的

片段.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

1 个答案:

答案 0 :(得分:2)

由于您正在使用Passenger,我认为您处于apache状态,因此您的请求不再通过Mongrel。如果是这样,您可以在应用程序的.htaccess目录中的public文件上建立规则。

Here's an explination on how to do it.