lib/rack/conditionalget.rb in rack-1.5.5 vs lib/rack/conditionalget.rb in rack-1.6.0.beta

- old
+ new

@@ -26,11 +26,14 @@ headers = Utils::HeaderHash.new(headers) if status == 200 && fresh?(env, headers) status = 304 headers.delete('Content-Type') headers.delete('Content-Length') - body = [] + original_body = body + body = Rack::BodyProxy.new([]) do + original_body.close if original_body.respond_to?(:close) + end end [status, headers, body] else @app.call(env) end @@ -59,9 +62,18 @@ modified_since and modified_since >= last_modified end def to_rfc2822(since) - Time.rfc2822(since) rescue nil + # shortest possible valid date is the obsolete: 1 Nov 97 09:55 A + # anything shorter is invalid, this avoids exceptions for common cases + # most common being the empty string + if since && since.length >= 16 + # NOTE: there is no trivial way to write this in a non execption way + # _rfc2822 returns a hash but is not that usable + Time.rfc2822(since) rescue nil + else + nil + end end end end