diff options
author | Eric Wong <e@80x24.org> | 2017-06-29 01:59:51 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-06-29 01:59:51 +0000 |
commit | 77b278b79e1a8ac6d2e4541fb0c6b51f552c23bc (patch) | |
tree | da36111eb9562607986e983bf6ba0fc833edc032 | |
parent | 0362a54dba92626582d42f3343c209b7cdb7e713 (diff) | |
download | rack-77b278b79e1a8ac6d2e4541fb0c6b51f552c23bc.tar.gz |
deflater: rely on frozen_string_literal
This improves readability of our code and can allow us to generate less garbage in Ruby 2.3+ for places where we didn't already use constants. We can also avoid the old constant lookups (and associated inline cache overhead) this way.
-rw-r--r-- | lib/rack/deflater.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb index 46d5b20a..9b798bab 100644 --- a/lib/rack/deflater.rb +++ b/lib/rack/deflater.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "zlib" require "time" # for Time.httpdate require 'rack/utils' @@ -52,7 +53,7 @@ module Rack case encoding when "gzip" headers['Content-Encoding'] = "gzip" - headers.delete(CONTENT_LENGTH) + headers.delete('Content-Length') mtime = headers.key?("Last-Modified") ? Time.httpdate(headers["Last-Modified"]) : Time.now [status, headers, GzipStream.new(body, mtime)] @@ -61,7 +62,7 @@ module Rack when nil message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found." bp = Rack::BodyProxy.new([message]) { body.close if body.respond_to?(:close) } - [406, {CONTENT_TYPE => "text/plain", CONTENT_LENGTH => message.length.to_s}, bp] + [406, {'Content-Type' => "text/plain", 'Content-Length' => message.length.to_s}, bp] end end @@ -102,13 +103,13 @@ module Rack # Skip compressing empty entity body responses and responses with # no-transform set. if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) || - headers[CACHE_CONTROL].to_s =~ /\bno-transform\b/ || + headers['Cache-Control'].to_s =~ /\bno-transform\b/ || (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) |