Changeset 1039

Show
Ignore:
Timestamp:
11/23/07 14:07:06 (1 year ago)
Author:
e.@brainspl.at
Message:

added config options for merb.yml :mongrel_x_sendfile that defaults to true. This means that mongre will emulate apaches X-Sendfile header internally by defult just liek it always has. If you want to let this header fall thru to yoru front end server then just set :mongrel_x_sendfile: false in your merb.yml and you're off to the races

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Rakefile

    r1038 r1039  
    1919 
    2020 
    21 @windows = (PLATFORM =~ /win32/) 
     21windows = (PLATFORM =~ /win32/) 
    2222 
    23 SUDO = @windows ? "" : (ENV["SUDO_COMMAND"] && "sudo") 
     23SUDO = windows ? "" : "sudo" 
    2424 
    2525setup_clean [ "pkg", "lib/*.bundle", "*.gem", "doc/rdoc", ".config", 'coverage', "cache"] 
     
    9393task :doc_rforge do 
    9494  sh %{rake doc} 
    95   sh %{#{SUDO} chmod -R 755 doc} unless @windows 
     95  sh %{#{SUDO} chmod -R 755 doc} unless windows 
    9696  sh %{/usr/bin/scp -r -p doc/rdoc/* ezmobius@rubyforge.org:/var/www/gforge-projects/merb} 
    9797end 
  • trunk/app_generators/merb/templates/config/merb.yml

    r727 r1039  
    3333#:cache_templates: true 
    3434 
     35# this is true if you want mongrel to emulate the X-Sendfile header internally, 
     36# false if you want it to fall thru to apache or whatever front end server you use. 
     37# true by default 
     38#:mongrel_x_sendfile: false 
     39 
    3540# Uncomment and set this if you want to run a drb server for upload progress 
    3641# or other drb services. 
  • trunk/lib/merb/mongrel_handler.rb

    r1038 r1039  
    2727  # directory of your site. This is set to the root of your merb app + '/public' 
    2828  # by default. 
    29   def initialize(dir, opts = {}) 
     29  def initialize(dir, mongrel_x_sendfile=true, opts = {}) 
    3030    @files = Mongrel::DirHandler.new(dir,false) 
     31    @mongrel_x_sendfile = mongrel_x_sendfile 
    3132  end 
    3233   
     
    108109       
    109110      if sendfile 
    110         benchmarks[:sendfile_time] = Time.now - start         
    111         MERB_LOGGER.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{ 
    112           benchmarks[:sendfile_time]} seconds") 
    113         file_status     = File.stat(sendfile) 
    114         response.status = 200 
    115         # Set the last modified times as well and etag for all files 
    116         response.header[Mongrel::Const::LAST_MODIFIED] = file_status.mtime.httpdate 
    117         # Calculated the same as apache, not sure how well the works on win32 
    118         response.header[Mongrel::Const::ETAG] = Mongrel::Const::ETAG_FORMAT % [file_status.mtime.to_i, file_status.size, file_status.ino] 
    119         # Send a status with out content length 
    120         response.send_status(file_status.size) 
    121         response.send_header 
    122         response.send_file(sendfile) 
     111        if @mongrel_x_sendfile 
     112          # we want to emulate X-Sendfile header internally in mongrel 
     113          benchmarks[:sendfile_time] = Time.now - start         
     114          MERB_LOGGER.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{ 
     115            benchmarks[:sendfile_time]} seconds") 
     116          file_status     = File.stat(sendfile) 
     117          response.status = 200 
     118          # Set the last modified times as well and etag for all files 
     119          response.header[Mongrel::Const::LAST_MODIFIED] = file_status.mtime.httpdate 
     120          # Calculated the same as apache, not sure how well the works on win32 
     121          response.header[Mongrel::Const::ETAG] = Mongrel::Const::ETAG_FORMAT % [file_status.mtime.to_i, file_status.size, file_status.ino] 
     122          # Send a status with out content length 
     123          response.send_status(file_status.size) 
     124          response.send_header 
     125          response.send_file(sendfile)   
     126        else 
     127          # we want to pass thru the X-Sendfile header so apache or whatever  
     128          # front server can handle it 
     129          response.header['X-Sendfile'] = sendfile 
     130          response.header['Content-length'] = clength || File.size(sendfile) 
     131          response.finished 
     132        end     
    123133      elsif controller.body.respond_to? :read 
    124134        response.send_status(clength) 
  • trunk/lib/merb/server.rb

    r1015 r1039  
    2020          :use_mutex              => true, 
    2121          :session_id_cookie_only => true, 
    22           :query_string_whitelist => [] 
     22          :query_string_whitelist => [], 
     23          :mongrel_x_sendfile     => true 
    2324        } 
    2425      end 
     
    604605          listener do 
    605606            uri( "/", :handler => MerbUploadHandler.new(@@merb_opts), :in_front => true) if @@merb_opts[:upload_path_match] 
    606             uri "/", :handler => MerbHandler.new(@@merb_opts[:merb_root]+'/public'
     607            uri "/", :handler => MerbHandler.new(@@merb_opts[:merb_root]+'/public', @@merb_opts[:mongrel_x_sendfile]
    607608            uri "/favicon.ico", :handler => Mongrel::Error404Handler.new("")  
    608609          end