diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-07-30 21:32:24 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-08-02 19:39:33 -0400 |
commit | b53f00690173797a39ff46e55dd25c20581c3d00 (patch) | |
tree | a8919d6e0c7029935a92a7fdbf7d373ce1684566 /actionpack/lib/action_dispatch/http/response.rb | |
parent | 503ce1d01ce6c8eee9818f4e76a9f880bb1a291d (diff) | |
download | rails-b53f00690173797a39ff46e55dd25c20581c3d00.tar.gz rails-b53f00690173797a39ff46e55dd25c20581c3d00.tar.bz2 rails-b53f00690173797a39ff46e55dd25c20581c3d00.zip |
Remove legacy processing and content_length
* convert_content_type! is handled by assign_default_content_type_and_charset!
* set_content_length! should be handled by the endpoint server. Otherwise
each middleware that modifies the body has to do the expensive work of
recalculating content_length.
* convert_language! appears to be legacy. There are no tests for this
* convert_cookies! should be handled by the new HeaderHash in Rack
* Use an integer for .status's internal representation to avoid needing to
do String manipulation just to find out the status
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 50 |
1 files changed, 10 insertions, 40 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 32cfb5ae44..03d1780b77 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -46,18 +46,22 @@ module ActionDispatch # :nodoc: @header = Rack::Utils::HeaderHash.new end + def status=(status) + @status = status.to_i + end + # The response code of the request def response_code - status.to_s[0,3].to_i rescue 0 + @status end # Returns a String to ensure compatibility with Net::HTTPResponse def code - status.to_s.split(' ')[0] + @status.to_s end def message - status.to_s.split(' ',2)[1] || StatusCodes::STATUS_CODES[response_code] + StatusCodes::STATUS_CODES[@status] end alias_method :status_message, :message @@ -143,10 +147,7 @@ module ActionDispatch # :nodoc: def prepare! assign_default_content_type_and_charset! handle_conditional_get! - set_content_length! - convert_content_type! - convert_language! - convert_cookies! + self["Set-Cookie"] ||= "" end def each(&callback) @@ -203,7 +204,7 @@ module ActionDispatch # :nodoc: self.etag = body if request && request.etag_matches?(etag) - self.status = '304 Not Modified' + self.status = 304 self.body = [] end @@ -214,7 +215,7 @@ module ActionDispatch # :nodoc: end def nonempty_ok_response? - ok = !status || status.to_s[0..2] == '200' + ok = !@status || @status == 200 ok && string_body? end @@ -238,36 +239,5 @@ module ActionDispatch # :nodoc: headers["Cache-Control"] = options.join(", ") end - - def convert_content_type! - headers['Content-Type'] ||= "text/html" - headers['Content-Type'] += "; charset=" + headers.delete('charset') if headers['charset'] - end - - # 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! - if status && status.to_s[0..2] == '204' - headers.delete('Content-Length') - elsif length = headers['Content-Length'] - headers['Content-Length'] = length.to_s - elsif string_body? && (!status || status.to_s[0..2] != '304') - headers["Content-Length"] = Rack::Utils.bytesize(body).to_s - end - end - - def convert_language! - headers["Content-Language"] = headers.delete("language") if headers["language"] - end - - def convert_cookies! - headers['Set-Cookie'] = - if header = headers['Set-Cookie'] - header = header.split("\n") if header.respond_to?(:to_str) - header.compact - else - [] - end - end end end |