Skip to content
Browse files

Make X-Sendfile default to "" so it works correctly in dev mode.

Provide a default in production.rb that can be modified, so that
people who care about sendfile performance in production mode can
get better performance easily.
  • Loading branch information...
1 parent 1979043 commit 56a86c2191e159448bd2644f105f629c34c85c48 @wycats wycats committed Mar 26, 2010
View
2 actionpack/lib/action_dispatch/railtie.rb
@@ -4,7 +4,7 @@
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
View
9 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"
@KieranP
KieranP added a note Mar 27, 2010

Misspelling? action_disaptch -> action_dispatch

@wycats
Ruby on Rails member
wycats added a note Mar 27, 2010

Fixed in a subsequent commit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ # 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
View
79 railties/test/application/configuration_test.rb
@@ -140,7 +140,7 @@ def teardown
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,86 +172,79 @@ def teardown
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
send_file __FILE__
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

1 comment on commit 56a86c2

@mislav
Ruby on Rails member
mislav commented on 56a86c2 Mar 27, 2010

Awesome. Was bitten by that

Please sign in to comment.
Something went wrong with that request. Please try again.