Skip to content
Browse files

Use status response accessor instead of the 'Status' header

  • Loading branch information...
1 parent 12e416a commit 3da1b94d07fbbd6cff342a822af1631ae167a9b8 @josh josh committed Dec 19, 2008
View
4 actionpack/lib/action_controller/base.rb
@@ -990,7 +990,7 @@ def erase_redirect_results #: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 @@ def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:no
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 ||= ''
View
2 actionpack/lib/action_controller/benchmarking.rb
@@ -83,7 +83,7 @@ def perform_action_with_benchmark
end
end
- log_message << " | #{headers["Status"]}"
+ log_message << " | #{response.status}"
log_message << " [#{complete_request_uri rescue "unknown"}]"
logger.info(log_message)
View
2 actionpack/lib/action_controller/caching/actions.rb
@@ -113,7 +113,7 @@ def path_options_for(controller, options)
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?
View
2 actionpack/lib/action_controller/caching/pages.rb
@@ -145,7 +145,7 @@ def cache_page(content = nil, options = nil)
private
def caching_allowed
- request.get? && response.headers['Status'].to_i == 200
+ request.get? && response.status.to_i == 200
end
end
end
View
3 actionpack/lib/action_controller/integration.rb
@@ -333,7 +333,8 @@ def process(method, path, parameters = nil, headers = nil)
# 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
View
6 actionpack/lib/action_controller/rack_process.rb
@@ -78,14 +78,8 @@ def initialize
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, []]
View
2 actionpack/lib/action_controller/rescue.rb
@@ -102,7 +102,7 @@ def rescue_action_in_public(exception) #:doc:
# 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
View
8 actionpack/lib/action_controller/response.rb
@@ -33,6 +33,7 @@ class AbstractResponse
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 @@ def initialize
@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 @@ def handle_conditional_get!
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 @@ def convert_content_type!
# 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
View
2 actionpack/lib/action_controller/test_process.rb
@@ -166,7 +166,7 @@ def url_encoded_request_parameters
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
View
2 actionpack/test/controller/caching_test.rb
@@ -169,7 +169,7 @@ def redirected
def forbidden
render :text => "Forbidden"
- headers["Status"] = "403 Forbidden"
+ response.status = "403 Forbidden"
end
def with_layout
View
6 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
View
4 actionpack/test/controller/render_test.rb
@@ -1147,11 +1147,11 @@ def test_head_with_custom_header
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|
View
4 actionpack/test/controller/send_file_test.rb
@@ -123,13 +123,13 @@ def test_send_file_headers!
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

0 comments on commit 3da1b94

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