diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-12-19 15:05:51 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-12-19 15:05:51 -0600 |
commit | 3da1b94d07fbbd6cff342a822af1631ae167a9b8 (patch) | |
tree | 9d5c87ce38143ca196aa4681fc5a7678fb330073 | |
parent | 12e416a04b764d0b212e04a53b770f60dc0d7071 (diff) | |
download | rails-3da1b94d07fbbd6cff342a822af1631ae167a9b8.tar.gz rails-3da1b94d07fbbd6cff342a822af1631ae167a9b8.tar.bz2 rails-3da1b94d07fbbd6cff342a822af1631ae167a9b8.zip |
Use status response accessor instead of the 'Status' header
-rw-r--r-- | actionpack/lib/action_controller/base.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/benchmarking.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/caching/actions.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/caching/pages.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/integration.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_controller/rack_process.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_controller/rescue.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/response.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_process.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/rack_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/send_file_test.rb | 4 |
13 files changed, 20 insertions, 27 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 454ef4ffac..eae17d6dd5 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -990,7 +990,7 @@ module ActionController #:nodoc: @performed_redirect = false response.redirected_to = nil response.redirected_to_method_params = nil - response.headers['Status'] = DEFAULT_RENDER_STATUS_CODE + response.status = DEFAULT_RENDER_STATUS_CODE response.headers.delete('Location') end @@ -1171,7 +1171,7 @@ module ActionController #:nodoc: def render_for_text(text = nil, status = nil, append_response = false) #:nodoc: @performed_render = true - response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) + response.status = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) if append_response response.body ||= '' diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index 732f774fbc..47377e5fa9 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -83,7 +83,7 @@ module ActionController #:nodoc: end end - log_message << " | #{headers["Status"]}" + log_message << " | #{response.status}" log_message << " [#{complete_request_uri rescue "unknown"}]" logger.info(log_message) diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 7c803a9830..34e1c3527f 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -113,7 +113,7 @@ module ActionController #:nodoc: end def caching_allowed(controller) - controller.request.get? && controller.response.headers['Status'].to_i == 200 + controller.request.get? && controller.response.status.to_i == 200 end def cache_layout? diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 22e4fbec43..bd3b5a5875 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -145,7 +145,7 @@ module ActionController #:nodoc: private def caching_allowed - request.get? && response.headers['Status'].to_i == 200 + request.get? && response.status.to_i == 200 end end end diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index 7590d5d710..8c2e3197df 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -333,7 +333,8 @@ module ActionController # Decorate responses from Rack Middleware and Rails Metal # as an AbstractResponse for the purposes of integration testing @response = AbstractResponse.new - @response.headers = @headers.merge('Status' => status.to_s) + @response.status = status.to_s + @response.headers = @headers @response.body = @body end diff --git a/actionpack/lib/action_controller/rack_process.rb b/actionpack/lib/action_controller/rack_process.rb index 8483f8e289..e7d00409ca 100644 --- a/actionpack/lib/action_controller/rack_process.rb +++ b/actionpack/lib/action_controller/rack_process.rb @@ -78,14 +78,8 @@ module ActionController #:nodoc: super() end - # Retrieve status from instance variable if has already been delete - def status - @status || super - end - def to_a(&block) @block = block - @status = headers.delete("Status") if [204, 304].include?(status.to_i) headers.delete("Content-Type") [status, headers.to_hash, []] diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index b8b0175b5f..5ef79a36ce 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -102,7 +102,7 @@ module ActionController #:nodoc: # doesn't exist, the body of the response will be left empty. def render_optional_error_file(status_code) status = interpret_status(status_code) - path = "#{Rails.public_path}/#{status[0,3]}.html" + path = "#{Rails.public_path}/#{status.to_s[0,3]}.html" if File.exist?(path) render :file => path, :status => status, :content_type => Mime::HTML else diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index 4c37f09215..e1bf5bb04d 100644 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -33,6 +33,7 @@ module ActionController # :nodoc: DEFAULT_HEADERS = { "Cache-Control" => "no-cache" } attr_accessor :request + attr_accessor :status # The body content (e.g. HTML) of the response, as a String. attr_accessor :body # The headers of the response, as a Hash. It maps header names to header values. @@ -46,9 +47,6 @@ module ActionController # :nodoc: @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], [] end - def status; headers['Status'] end - def status=(status) headers['Status'] = status end - def location; headers['Location'] end def location=(url) headers['Location'] = url end @@ -161,7 +159,7 @@ module ActionController # :nodoc: end def nonempty_ok_response? - ok = !status || status[0..2] == '200' + ok = !status || status.to_s[0..2] == '200' ok && body.is_a?(String) && !body.empty? end @@ -186,7 +184,7 @@ module ActionController # :nodoc: # Don't set the Content-Length for block-based bodies as that would mean reading it all into memory. Not nice # for, say, a 2GB streaming file. def set_content_length! - unless body.respond_to?(:call) || (status && status[0..2] == '304') + unless body.respond_to?(:call) || (status && status.to_s[0..2] == '304') self.headers["Content-Length"] ||= body.size end end diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index c613d6b862..d3c66dd5f2 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -166,7 +166,7 @@ module ActionController #:nodoc: module TestResponseBehavior #:nodoc: # The response code of the request def response_code - status[0,3].to_i rescue 0 + status.to_s[0,3].to_i rescue 0 end # Returns a String to ensure compatibility with Net::HTTPResponse diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index ddf140ac3a..e24bb00bc7 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -169,7 +169,7 @@ class ActionCachingTestController < ActionController::Base def forbidden render :text => "Forbidden" - headers["Status"] = "403 Forbidden" + response.status = "403 Forbidden" end def with_layout diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 3a8a00b7d7..51f43290d2 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -271,17 +271,17 @@ class RackResponseHeadersTest < BaseRackTest def setup super @response = ActionController::RackResponse.new - @response.headers['Status'] = "200 OK" + @response.status = "200 OK" end def test_content_type [204, 304].each do |c| - @response.headers['Status'] = c.to_s + @response.status = c.to_s assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" end [200, 302, 404, 500].each do |c| - @response.headers['Status'] = c.to_s + @response.status = c.to_s assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index a6721fd903..e0f05d654c 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1147,11 +1147,11 @@ class RenderTest < ActionController::TestCase def test_head_with_symbolic_status get :head_with_symbolic_status, :status => "ok" - assert_equal "200 OK", @response.headers["Status"] + assert_equal "200 OK", @response.status assert_response :ok get :head_with_symbolic_status, :status => "not_found" - assert_equal "404 Not Found", @response.headers["Status"] + assert_equal "404 Not Found", @response.status assert_response :not_found ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index ffbaa457f8..c4349bfc7f 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -123,13 +123,13 @@ class SendFileTest < Test::Unit::TestCase define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } assert_nothing_raised { assert_not_nil process(method) } - assert_equal '500 Internal Server Error', @response.headers['Status'] + assert_equal '500 Internal Server Error', @response.status end define_method "test_default_send_#{method}_status" do @controller.options = { :stream => false } assert_nothing_raised { assert_not_nil process(method) } - assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.headers['Status'] + assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status end end end |