I came across an issue that caused bytesize() to throw an exception because it was being asked to return the size of nil when an HTTP response has status is 204 (no content).
The test on line 16 of content_length.rb should prevent it from ever reaching this code, but neglects to convert status (an instance of String) to an int before checking for inclusion in the the Set instance named by the constant STATUS_WITH_NO_ENTITY_BODY, which contains integers.
Please accept the following patch:
diff --git a/lib/rack/content_length.rb b/lib/rack/content_length.rb
index 1e56d43..ba72ef2 100644
--- a/lib/rack/content_length.rb
+++ b/lib/rack/content_length.rb
@@ -13,7 +13,7 @@ module Rack
status, headers, body = @app.call(env)
headers = HeaderHash.new(headers)
- if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
+ if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
!headers['Content-Length'] &&
!headers['Transfer-Encoding'] &&
(body.respond_to?(:to_ary) || body.respond_to?(:to_str))
I hope someone will contact me to let me know whether this has been accepted and what release it will appear in. Thank you and G-d bless.
Larry Siden, 734-926-9614, http://umich.edu/~lsiden
The United States is a nation of laws, badly written and randomly enforced.
--Frank Zappa 1940-1993