Mongrel :: Dirhandler equivalent for passenger

I use Mongrel :: DirHandler to manage response headers for static files - this works fine on my dev machine. My production machine uses Passenger, so my headers are not set. How to manage headers for static files when using Passenger?

fragment from my .rb environment:

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 
+3
source share
1 answer

Since you are using Passenger, I assume you are under Apache, so your request no longer goes through Mongrel. If so, you can set the rules in the .htaccess file inside the public directory of your application.

Here is an explanation of how to do this.

+2
source

All Articles