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)
46
46
# https://lists.w3.org/Archives/Public/ietf-http-wg/2014JanMar/1179.html
47
47
return response if response . partial?
48
48
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
+
49
54
# Ensure that caches are aware we are varying the response based on the accept-encoding request header:
50
55
response . headers . add ( "vary" , "accept-encoding" )
51
56
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" ]
54
58
if content_type = response . headers [ "content-type" ] and @content_types =~ content_type
55
- body = response . body
56
-
57
59
accept_encoding . each do |name |
58
60
if wrapper = @wrappers [ name ]
59
61
response . headers [ "content-encoding" ] = name
Original file line number Diff line number Diff line change 79
79
expect ( response . read ) . to be == "Hello World!"
80
80
end
81
81
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
82
101
end
You can’t perform that action at this time.
0 commit comments