Skip to content

Commit

Permalink
Ensure that deflater always closes bodies.
Browse files Browse the repository at this point in the history
Closes #349
  • Loading branch information
James Tucker committed Jan 4, 2013
1 parent e51e28d commit 35c0890
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rack/deflater.rb
Expand Up @@ -45,6 +45,7 @@ def call(env)
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
Expand All @@ -64,6 +65,7 @@ def each(&block)
gzip.write(part)
gzip.flush
}
ensure
@body.close if @body.respond_to?(:close)
gzip.close
@writer = nil
Expand All @@ -90,9 +92,11 @@ def initialize(body)
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
Expand Down

0 comments on commit 35c0890

Please sign in to comment.