From cae4b5c539199182f8f6e6ba911976a19c51fda8 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 11 Oct 2009 14:00:16 -0500 Subject: [PATCH] Enable X-Sendfile support under Passenger Passenger doesn't behave like a proxy server. But it does support X-Sendfile. So let's make use of that. --- app/controllers/application_controller.rb | 3 ++- app/controllers/file_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4f921674..75d2a638 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -87,7 +87,8 @@ class ApplicationController < ActionController::Base original_options[:type] ||= (FILE_TYPES[File.extname(file_name)] or 'application/octet-stream') original_options[:disposition] ||= (DISPOSITION[original_options[:type]] or 'attachment') original_options[:stream] ||= false - original_options[:x_sendfile] = true if request.env.include?('HTTP_X_SENDFILE_TYPE') && request.remote_addr == LOCALHOST + original_options[:x_sendfile] = true if request.env.include?('HTTP_X_SENDFILE_TYPE') && + ( request.remote_addr == LOCALHOST || defined?(PhusionPassenger) ) original_options end diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index 8d8dae15..9585a278 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -7,8 +7,8 @@ class FileController < ApplicationController layout 'default' - before_filter :dnsbl_check, :check_authorized - before_filter :check_allow_uploads, :except => [:file, :blahtex_png] + before_filter :check_authorized + before_filter :check_allow_uploads, :dnsbl_check, :except => [:file, :blahtex_png] def file @file_name = params['id']