File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed
Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -46,14 +46,16 @@ def call(request)
4646 # https://lists.w3.org/Archives/Public/ietf-http-wg/2014JanMar/1179.html
4747 return response if response . partial?
4848
49+ body = response . body
50+
51+ # If there is no response body, there is nothing to encode:
52+ return response if body . nil? or body . empty?
53+
4954 # Ensure that caches are aware we are varying the response based on the accept-encoding request header:
5055 response . headers . add ( "vary" , "accept-encoding" )
5156
52- # TODO use http-accept and sort by priority
53- if !response . body . empty? and accept_encoding = request . headers [ "accept-encoding" ]
57+ if accept_encoding = request . headers [ "accept-encoding" ]
5458 if content_type = response . headers [ "content-type" ] and @content_types =~ content_type
55- body = response . body
56-
5759 accept_encoding . each do |name |
5860 if wrapper = @wrappers [ name ]
5961 response . headers [ "content-encoding" ] = name
Original file line number Diff line number Diff line change 7979 expect ( response . read ) . to be == "Hello World!"
8080 end
8181 end
82+
83+ with "nil body" do
84+ let ( :app ) do
85+ app = -> ( request ) {
86+ Protocol ::HTTP ::Response [ 200 , Protocol ::HTTP ::Headers [ "content-type" => "text/plain" ] , nil ]
87+ }
88+ end
89+
90+ let ( :client ) { subject . new ( app ) }
91+
92+ it "does not compress response" do
93+ response = client . get ( "/index" , { "accept-encoding" => "gzip" } )
94+
95+ expect ( response ) . to be ( :success? )
96+ expect ( response . headers ) . not . to have_keys ( "content-encoding" )
97+
98+ expect ( response . read ) . to be == nil
99+ end
100+ end
82101end
You can’t perform that action at this time.
0 commit comments