aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2011-08-07 12:34:49 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2011-08-07 13:11:50 -0300
commit8845ae683e2688bc619baade49510c17e978518f (patch)
tree9d812eeb66aa12ba095118dbf2af28baf11343c2
parent888539c54167964957b97328e3e863d91fa9c240 (diff)
downloadrails-8845ae683e2688bc619baade49510c17e978518f.tar.gz
rails-8845ae683e2688bc619baade49510c17e978518f.tar.bz2
rails-8845ae683e2688bc619baade49510c17e978518f.zip
x_sendfile_header now defaults to nil and production.rb env file doesn't
set a particular value for it. This allows servers to set it through X-Sendfile-Type, read https://github.com/rack/rack/blob/master/lib/rack/sendfile.rb for more info. Anyways you can force this value in your production.rb
-rw-r--r--actionpack/lib/action_controller/metal/data_streaming.rb2
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb2
-rw-r--r--railties/lib/rails/application.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt4
-rw-r--r--railties/test/application/middleware/sendfile_test.rb3
-rw-r--r--railties/test/application/middleware_test.rb8
6 files changed, 7 insertions, 16 deletions
diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb
index 0785fe9679..5e077dd7bd 100644
--- a/actionpack/lib/action_controller/metal/data_streaming.rb
+++ b/actionpack/lib/action_controller/metal/data_streaming.rb
@@ -17,7 +17,7 @@ module ActionController #:nodoc:
protected
# Sends the file. This uses a server-appropriate method (such as X-Sendfile)
# via the Rack::Sendfile middleware. The header to use is set via
- # config.action_dispatch.x_sendfile_header, and defaults to "X-Sendfile".
+ # config.action_dispatch.x_sendfile_header.
# Your server can also configure this for you by setting the X-Sendfile-Type header.
#
# Be careful to sanitize the path parameter if it is coming from a web
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index f51cc3711b..fbda1f8442 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -4,7 +4,7 @@ require "rails"
module ActionDispatch
class Railtie < Rails::Railtie
config.action_dispatch = ActiveSupport::OrderedOptions.new
- config.action_dispatch.x_sendfile_header = ""
+ config.action_dispatch.x_sendfile_header = nil
config.action_dispatch.ip_spoofing_check = true
config.action_dispatch.show_exceptions = true
config.action_dispatch.best_standards_support = true
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index fb60ddd9b5..9e2f1a4b7a 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -163,9 +163,7 @@ module Rails
middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods
middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
- if config.action_dispatch.x_sendfile_header.present?
- middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
- end
+ middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
middleware.use ::ActionDispatch::Reloader unless config.cache_classes
middleware.use ::ActionDispatch::Callbacks
middleware.use ::ActionDispatch::Cookies
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 06ed890e05..de56d47688 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -15,8 +15,8 @@
config.assets.compress = true
# Specifies the header that your server uses for sending files
- # (comment out if your front-end server doesn't support this)
- config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
diff --git a/railties/test/application/middleware/sendfile_test.rb b/railties/test/application/middleware/sendfile_test.rb
index c7a1c573f9..d2ad2668bb 100644
--- a/railties/test/application/middleware/sendfile_test.rb
+++ b/railties/test/application/middleware/sendfile_test.rb
@@ -27,11 +27,12 @@ module ApplicationTests
end
# x_sendfile_header middleware
- test "config.action_dispatch.x_sendfile_header defaults to ''" do
+ test "config.action_dispatch.x_sendfile_header defaults to nil" do
make_basic_app
simple_controller
get "/"
+ assert !last_response.headers["X-Sendfile"]
assert_equal File.read(__FILE__), last_response.body
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index bed5ba503f..6a0a272073 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -20,8 +20,6 @@ module ApplicationTests
end
test "default middleware stack" do
- add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'"
-
boot!
assert_equal [
@@ -49,12 +47,6 @@ module ApplicationTests
], middleware
end
- test "Rack::Sendfile is not included by default" do
- boot!
-
- assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header"
- end
-
test "Rack::Cache is present when action_controller.perform_caching is set" do
add_to_config "config.action_controller.perform_caching = true"