lib/rack/deflater.rb in rack-1.6.13 vs lib/rack/deflater.rb in rack-2.0.0.alpha

- old
+ new

@@ -43,11 +43,11 @@ encoding = Utils.select_best_encoding(%w(gzip deflate identity), request.accept_encoding) # Set the Vary HTTP header. - vary = headers["Vary"].to_s.split(",").map { |v| v.strip } + vary = headers["Vary"].to_s.split(",").map(&:strip) unless vary.include?("*") || vary.include?("Accept-Encoding") headers["Vary"] = vary.push("Accept-Encoding").join(",") end case encoding @@ -116,13 +116,13 @@ end def each deflator = ::Zlib::Deflate.new(*DEFLATE_ARGS) @body.each { |part| yield deflator.deflate(part, Zlib::SYNC_FLUSH) } - yield deflator.finish - nil + yield fin = deflator.finish ensure + deflator.finish unless fin deflator.close end def close return if @closed @@ -141,10 +141,10 @@ (headers['Content-Encoding'] && headers['Content-Encoding'] !~ /\bidentity\b/) return false end # Skip if @compressible_types are given and does not include request's content type - return false if @compressible_types && !(headers.has_key?('Content-Type') && @compressible_types.include?(headers['Content-Type'][/[^;]*/])) + return false if @compressible_types && !(headers.has_key?(CONTENT_TYPE) && @compressible_types.include?(headers[CONTENT_TYPE][/[^;]*/])) # Skip if @condition lambda is given and evaluates to false return false if @condition && !@condition.call(env, status, headers, body) true