From 5e2bd08023344f3fd4675e80203a10967ffe9000 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 23 Feb 2010 17:03:06 -0800 Subject: Makes send_file work again by deferring to Rack::Sendfile. * Add the Rack::Sendfile middleware * Make the header to use configurable via config.action_dispatch.x_sendfile_header (default to "X-Sendfile"). * Add Railties tests to confirm that these work * Remove the :stream, :buffer_size, and :x_senfile default options to send_file * Change the log subscriber to always say "Sent file" * Add deprecation warnings for options that are now no-ops Note that servers can configure this by setting X-Sendfile-Type. Hosting companies and those creating packages of servers specially designed for Rails applications are encouraged to specify this header so that this can work transparently. --- railties/test/application/configuration_test.rb | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'railties/test/application/configuration_test.rb') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 7ca605ec23..3e03a01ff3 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -171,5 +171,60 @@ module ApplicationTests get "/" assert $prepared end + + test "config.action_dispatch.x_sendfile_header defaults to X-Sendfile" do + require "rails" + require "action_controller/railtie" + + class MyApp < Rails::Application + config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + end + + MyApp.initialize! + + class ::OmgController < ActionController::Base + def index + send_file __FILE__ + end + end + + MyApp.routes.draw do + match "/" => "omg#index" + end + + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal File.expand_path(__FILE__), last_response.headers["X-Sendfile"] + end + + test "config.action_dispatch.x_sendfile_header is sent to Rack::Sendfile" do + require "rails" + require "action_controller/railtie" + + class MyApp < Rails::Application + config.action_controller.session = { :key => "_myapp_session", :secret => "3b7cd727ee24e8444053437c36cc66c4" } + config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File' + end + + MyApp.initialize! + + class ::OmgController < ActionController::Base + def index + send_file __FILE__ + end + end + + MyApp.routes.draw do + match "/" => "omg#index" + end + + require 'rack/test' + extend Rack::Test::Methods + + get "/" + assert_equal File.expand_path(__FILE__), last_response.headers["X-Lighttpd-Send-File"] + end end end -- cgit v1.2.3