From 3da1b94d07fbbd6cff342a822af1631ae167a9b8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 19 Dec 2008 15:05:51 -0600 Subject: Use status response accessor instead of the 'Status' header --- actionpack/lib/action_controller/base.rb | 4 ++-- actionpack/lib/action_controller/benchmarking.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 2 +- actionpack/lib/action_controller/caching/pages.rb | 2 +- actionpack/lib/action_controller/integration.rb | 3 ++- actionpack/lib/action_controller/rack_process.rb | 6 ------ actionpack/lib/action_controller/rescue.rb | 2 +- actionpack/lib/action_controller/response.rb | 8 +++----- actionpack/lib/action_controller/test_process.rb | 2 +- 9 files changed, 12 insertions(+), 19 deletions(-) (limited to 'actionpack/lib') 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 -- cgit v1.2.3