aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt9
-rw-r--r--railties/test/application/configuration_test.rb79
3 files changed, 46 insertions, 44 deletions
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index 430c90e515..563df0f256 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 = "X-Sendfile"
+ config.action_dispatch.x_sendfile_header = ""
config.action_dispatch.ip_spoofing_check = true
# Prepare dispatcher callbacks and run 'prepare' callbacks
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 917052c3df..44d739e448 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
@@ -9,6 +9,15 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
+ # Specifies the header that your server uses for sending files
+ config.action_disaptch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
# See everything in the log (default is :info)
# config.log_level = :debug
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 1b6c657d6d..68ca2acaad 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -140,7 +140,7 @@ module ApplicationTests
require "#{app_path}/config/environment"
end
end
-
+
test "filter_parameters should be able to set via config.filter_parameters" do
add_to_config <<-RUBY
config.filter_parameters += [ :foo, 'bar', lambda { |key, value|
@@ -172,16 +172,27 @@ module ApplicationTests
assert $prepared
end
- test "config.action_dispatch.x_sendfile_header defaults to X-Sendfile" do
+ def make_basic_app
require "rails"
require "action_controller/railtie"
- class MyApp < Rails::Application
- config.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
- config.session_store :cookie_store, :key => "_myapp_session"
+ app = Class.new(Rails::Application)
+
+ yield app if block_given?
+
+ app.config.session_store :disabled
+ app.initialize!
+
+ app.routes.draw do
+ match "/" => "omg#index"
end
- MyApp.initialize!
+ require 'rack/test'
+ extend Rack::Test::Methods
+ end
+
+ test "config.action_dispatch.x_sendfile_header defaults to ''" do
+ make_basic_app
class ::OmgController < ActionController::Base
def index
@@ -189,69 +200,51 @@ module ApplicationTests
end
end
- MyApp.routes.draw do
- match "/" => "omg#index"
+ get "/"
+ assert_equal File.read(__FILE__), last_response.body
+ end
+
+ test "config.action_dispatch.x_sendfile_header can be set" do
+ make_basic_app do |app|
+ app.config.action_dispatch.x_sendfile_header = "X-Sendfile"
end
- require 'rack/test'
- extend Rack::Test::Methods
+ class ::OmgController < ActionController::Base
+ def index
+ send_file __FILE__
+ end
+ end
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.cookie_secret = "3b7cd727ee24e8444053437c36cc66c4"
- config.session_store :cookie_store, :key => "_myapp_session"
- config.action_dispatch.x_sendfile_header = 'X-Lighttpd-Send-File'
+ make_basic_app do |app|
+ app.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
test "protect from forgery is the default in a new app" do
- require "rails"
- require "action_controller/railtie"
-
- class MyApp < Rails::Application
- config.session_store :disabled
-
- routes.draw do
- match "/" => "omg#index"
- end
+ make_basic_app
- class ::OmgController < ActionController::Base
- protect_from_forgery
+ class ::OmgController < ActionController::Base
+ protect_from_forgery
- def index
- render :inline => "<%= csrf_meta_tag %>"
- end
+ def index
+ render :inline => "<%= csrf_meta_tag %>"
end
end
- require 'rack/test'
- extend Rack::Test::Methods
-
get "/"
assert last_response.body =~ /csrf\-param/
end