Skip to content
This repository
Browse code

Use status response accessor instead of the 'Status' header

  • Loading branch information...
commit 3da1b94d07fbbd6cff342a822af1631ae167a9b8 1 parent 12e416a
Joshua Peek josh authored
4 actionpack/lib/action_controller/base.rb
@@ -990,7 +990,7 @@ def erase_redirect_results #:nodoc:
990 990 @performed_redirect = false
991 991 response.redirected_to = nil
992 992 response.redirected_to_method_params = nil
993   - response.headers['Status'] = DEFAULT_RENDER_STATUS_CODE
  993 + response.status = DEFAULT_RENDER_STATUS_CODE
994 994 response.headers.delete('Location')
995 995 end
996 996
@@ -1171,7 +1171,7 @@ def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:no
1171 1171 def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
1172 1172 @performed_render = true
1173 1173
1174   - response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE)
  1174 + response.status = interpret_status(status || DEFAULT_RENDER_STATUS_CODE)
1175 1175
1176 1176 if append_response
1177 1177 response.body ||= ''
2  actionpack/lib/action_controller/benchmarking.rb
@@ -83,7 +83,7 @@ def perform_action_with_benchmark
83 83 end
84 84 end
85 85
86   - log_message << " | #{headers["Status"]}"
  86 + log_message << " | #{response.status}"
87 87 log_message << " [#{complete_request_uri rescue "unknown"}]"
88 88
89 89 logger.info(log_message)
2  actionpack/lib/action_controller/caching/actions.rb
@@ -113,7 +113,7 @@ def path_options_for(controller, options)
113 113 end
114 114
115 115 def caching_allowed(controller)
116   - controller.request.get? && controller.response.headers['Status'].to_i == 200
  116 + controller.request.get? && controller.response.status.to_i == 200
117 117 end
118 118
119 119 def cache_layout?
2  actionpack/lib/action_controller/caching/pages.rb
@@ -145,7 +145,7 @@ def cache_page(content = nil, options = nil)
145 145
146 146 private
147 147 def caching_allowed
148   - request.get? && response.headers['Status'].to_i == 200
  148 + request.get? && response.status.to_i == 200
149 149 end
150 150 end
151 151 end
3  actionpack/lib/action_controller/integration.rb
@@ -333,7 +333,8 @@ def process(method, path, parameters = nil, headers = nil)
333 333 # Decorate responses from Rack Middleware and Rails Metal
334 334 # as an AbstractResponse for the purposes of integration testing
335 335 @response = AbstractResponse.new
336   - @response.headers = @headers.merge('Status' => status.to_s)
  336 + @response.status = status.to_s
  337 + @response.headers = @headers
337 338 @response.body = @body
338 339 end
339 340
6 actionpack/lib/action_controller/rack_process.rb
@@ -78,14 +78,8 @@ def initialize
78 78 super()
79 79 end
80 80
81   - # Retrieve status from instance variable if has already been delete
82   - def status
83   - @status || super
84   - end
85   -
86 81 def to_a(&block)
87 82 @block = block
88   - @status = headers.delete("Status")
89 83 if [204, 304].include?(status.to_i)
90 84 headers.delete("Content-Type")
91 85 [status, headers.to_hash, []]
2  actionpack/lib/action_controller/rescue.rb
@@ -102,7 +102,7 @@ def rescue_action_in_public(exception) #:doc:
102 102 # doesn't exist, the body of the response will be left empty.
103 103 def render_optional_error_file(status_code)
104 104 status = interpret_status(status_code)
105   - path = "#{Rails.public_path}/#{status[0,3]}.html"
  105 + path = "#{Rails.public_path}/#{status.to_s[0,3]}.html"
106 106 if File.exist?(path)
107 107 render :file => path, :status => status, :content_type => Mime::HTML
108 108 else
8 actionpack/lib/action_controller/response.rb
@@ -33,6 +33,7 @@ class AbstractResponse
33 33 DEFAULT_HEADERS = { "Cache-Control" => "no-cache" }
34 34 attr_accessor :request
35 35
  36 + attr_accessor :status
36 37 # The body content (e.g. HTML) of the response, as a String.
37 38 attr_accessor :body
38 39 # The headers of the response, as a Hash. It maps header names to header values.
@@ -46,9 +47,6 @@ def initialize
46 47 @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
47 48 end
48 49
49   - def status; headers['Status'] end
50   - def status=(status) headers['Status'] = status end
51   -
52 50 def location; headers['Location'] end
53 51 def location=(url) headers['Location'] = url end
54 52
@@ -161,7 +159,7 @@ def handle_conditional_get!
161 159 end
162 160
163 161 def nonempty_ok_response?
164   - ok = !status || status[0..2] == '200'
  162 + ok = !status || status.to_s[0..2] == '200'
165 163 ok && body.is_a?(String) && !body.empty?
166 164 end
167 165
@@ -186,7 +184,7 @@ def convert_content_type!
186 184 # Don't set the Content-Length for block-based bodies as that would mean reading it all into memory. Not nice
187 185 # for, say, a 2GB streaming file.
188 186 def set_content_length!
189   - unless body.respond_to?(:call) || (status && status[0..2] == '304')
  187 + unless body.respond_to?(:call) || (status && status.to_s[0..2] == '304')
190 188 self.headers["Content-Length"] ||= body.size
191 189 end
192 190 end
2  actionpack/lib/action_controller/test_process.rb
@@ -166,7 +166,7 @@ def url_encoded_request_parameters
166 166 module TestResponseBehavior #:nodoc:
167 167 # The response code of the request
168 168 def response_code
169   - status[0,3].to_i rescue 0
  169 + status.to_s[0,3].to_i rescue 0
170 170 end
171 171
172 172 # Returns a String to ensure compatibility with Net::HTTPResponse
2  actionpack/test/controller/caching_test.rb
@@ -169,7 +169,7 @@ def redirected
169 169
170 170 def forbidden
171 171 render :text => "Forbidden"
172   - headers["Status"] = "403 Forbidden"
  172 + response.status = "403 Forbidden"
173 173 end
174 174
175 175 def with_layout
6 actionpack/test/controller/rack_test.rb
@@ -271,17 +271,17 @@ class RackResponseHeadersTest < BaseRackTest
271 271 def setup
272 272 super
273 273 @response = ActionController::RackResponse.new
274   - @response.headers['Status'] = "200 OK"
  274 + @response.status = "200 OK"
275 275 end
276 276
277 277 def test_content_type
278 278 [204, 304].each do |c|
279   - @response.headers['Status'] = c.to_s
  279 + @response.status = c.to_s
280 280 assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
281 281 end
282 282
283 283 [200, 302, 404, 500].each do |c|
284   - @response.headers['Status'] = c.to_s
  284 + @response.status = c.to_s
285 285 assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
286 286 end
287 287 end
4 actionpack/test/controller/render_test.rb
@@ -1147,11 +1147,11 @@ def test_head_with_custom_header
1147 1147
1148 1148 def test_head_with_symbolic_status
1149 1149 get :head_with_symbolic_status, :status => "ok"
1150   - assert_equal "200 OK", @response.headers["Status"]
  1150 + assert_equal "200 OK", @response.status
1151 1151 assert_response :ok
1152 1152
1153 1153 get :head_with_symbolic_status, :status => "not_found"
1154   - assert_equal "404 Not Found", @response.headers["Status"]
  1154 + assert_equal "404 Not Found", @response.status
1155 1155 assert_response :not_found
1156 1156
1157 1157 ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
4 actionpack/test/controller/send_file_test.rb
@@ -123,13 +123,13 @@ def test_send_file_headers!
123 123 define_method "test_send_#{method}_status" do
124 124 @controller.options = { :stream => false, :status => 500 }
125 125 assert_nothing_raised { assert_not_nil process(method) }
126   - assert_equal '500 Internal Server Error', @response.headers['Status']
  126 + assert_equal '500 Internal Server Error', @response.status
127 127 end
128 128
129 129 define_method "test_default_send_#{method}_status" do
130 130 @controller.options = { :stream => false }
131 131 assert_nothing_raised { assert_not_nil process(method) }
132   - assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.headers['Status']
  132 + assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status
133 133 end
134 134 end
135 135 end

0 comments on commit 3da1b94

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