lib/rack/deflater.rb in rack-1.3.6 vs lib/rack/deflater.rb in rack-1.3.7

- old
+ new

@@ -43,10 +43,11 @@ headers.delete('Content-Length') [status, headers, DeflateStream.new(body)] when "identity" [status, headers, body] when nil + body.close if body.respond_to?(:close) message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found." [406, {"Content-Type" => "text/plain", "Content-Length" => message.length.to_s}, [message]] end end @@ -62,10 +63,11 @@ gzip.mtime = @mtime @body.each { |part| gzip.write(part) gzip.flush } + ensure @body.close if @body.respond_to?(:close) gzip.close @writer = nil end @@ -88,12 +90,14 @@ end def each deflater = ::Zlib::Deflate.new(*DEFLATE_ARGS) @body.each { |part| yield deflater.deflate(part, Zlib::SYNC_FLUSH) } - @body.close if @body.respond_to?(:close) yield deflater.finish nil + ensure + @body.close if @body.respond_to?(:close) + deflater.close end end end end