aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-02-23 17:03:06 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-02-23 17:06:35 -0800
commit5e2bd08023344f3fd4675e80203a10967ffe9000 (patch)
tree4e1b647bba47175b6ab9d0f054d4baba2224e221 /railties
parenta73f682e43016de520510e015802c48c9947a05c (diff)
downloadrails-5e2bd08023344f3fd4675e80203a10967ffe9000.tar.gz
rails-5e2bd08023344f3fd4675e80203a10967ffe9000.tar.bz2
rails-5e2bd08023344f3fd4675e80203a10967ffe9000.zip
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.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/configuration.rb1
-rw-r--r--railties/test/application/configuration_test.rb55
2 files changed, 56 insertions, 0 deletions
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 50675d19b8..811c3a9fd9 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -12,6 +12,7 @@ module Rails
middleware.use('::Rack::Runtime')
middleware.use('::Rails::Rack::Logger')
middleware.use('::ActionDispatch::ShowExceptions', lambda { Rails.application.config.consider_all_requests_local })
+ middleware.use('::Rack::Sendfile', lambda { Rails.application.config.action_dispatch.x_sendfile_header })
middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
middleware.use('::ActionDispatch::Cookies')
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
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