Permalink
Browse files

Fixed that HEAD should return the proper Content-Length header (that …

…is, actually use @body.size, not just 0) [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5622 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent fe1e771 commit c3cbd6b80617f971e5449a314f309f11ca903110 @dhh dhh committed Nov 23, 2006
Showing with 18 additions and 8 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +16 −8 actionpack/lib/action_controller/cgi_process.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*1.13.0 RC1* (November 22nd, 2006)
+* Fixed that HEAD should return the proper Content-Length header (that is, actually use @body.size, not just 0) [DHH]
+
* Added GET-masquarading for HEAD, so request.method will return :get even for HEADs. This will help anyone relying on case request.method to automatically work with HEAD and map.resources will also allow HEADs to all GET actions. Rails automatically throws away the response content in a reply to HEAD, so you don't even need to worry about that. If you, for whatever reason, still need to distinguish between GET and HEAD in some edge case, you can use Request#head? and even Request.headers["REQUEST_METHOD"] for get the "real" answer. Closes #6694 [DHH]
* Update Routing to complain when :controller is not specified by a route. Closes #6669. [Nicholas Seckar]
View
24 actionpack/lib/action_controller/cgi_process.rb
@@ -171,7 +171,9 @@ def initialize(cgi)
end
def out(output = $stdout)
- convert_content_type!(@headers)
+ convert_content_type!
+ set_content_length!
+
output.binmode if output.respond_to?(:binmode)
output.sync = false if output.respond_to?(:sync=)
@@ -196,16 +198,22 @@ def out(output = $stdout)
end
private
- def convert_content_type!(headers)
- if header = headers.delete("Content-Type")
- headers["type"] = header
+ def convert_content_type!
+ if content_type = @headers.delete("Content-Type")
+ @headers["type"] = content_type
end
- if header = headers.delete("Content-type")
- headers["type"] = header
+ if content_type = @headers.delete("Content-type")
+ @headers["type"] = content_type
end
- if header = headers.delete("content-type")
- headers["type"] = header
+ if content_type = @headers.delete("content-type")
+ @headers["type"] = content_type
end
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!
+ @headers["Content-Length"] = @body.size unless @body.respond_to?(:call)
+ end
end
end

0 comments on commit c3cbd6b

Please sign in to comment.