Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongrel::DirHandler

Tags:

mongrel

I'm using Mongrel::DirHandlery to control response headers for static files. How do I control headers for static files when using Passenger?

snippet from my test.rb:

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

        if req_path =~ /((\/image)|javascript|stylesheet)/
          response.header['Cache-Control'] = 'max-age=-2'
          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
like image 409
Andy Gaskell Avatar asked Mar 21 '26 21:03

Andy Gaskell


1 Answers

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.

like image 162
changelog Avatar answered Mar 24 '26 10:03

changelog