@@ -165,36 +165,31 @@ def push(path, headers = nil, scheme = @scheme, authority = @authority)
165
165
166
166
def send_response ( response )
167
167
if response . nil?
168
- @stream . send_headers ( nil , NO_RESPONSE , ::Protocol ::HTTP2 ::END_STREAM )
169
- elsif response . body? && !self . head?
170
- pseudo_headers = [
171
- [ STATUS , response . status ] ,
172
- ]
173
-
174
- if protocol = response . protocol
175
- pseudo_headers << [ PROTOCOL , protocol ]
176
- end
177
-
178
- if length = response . body . length
179
- pseudo_headers << [ CONTENT_LENGTH , length ]
180
- end
181
-
182
- headers = ::Protocol ::HTTP ::Headers ::Merged . new (
183
- pseudo_headers ,
184
- response . headers
185
- )
186
-
168
+ return @stream . send_headers ( nil , NO_RESPONSE , ::Protocol ::HTTP2 ::END_STREAM )
169
+ end
170
+
171
+ protocol_headers = [
172
+ [ STATUS , response . status ] ,
173
+ ]
174
+
175
+ if protocol = response . protocol
176
+ protocol_headers << [ PROTOCOL , protocol ]
177
+ end
178
+
179
+ if length = response . body &.length
180
+ protocol_headers << [ CONTENT_LENGTH , length ]
181
+ end
182
+
183
+ headers = ::Protocol ::HTTP ::Headers ::Merged . new ( protocol_headers , response . headers )
184
+
185
+ if body = response . body and !self . head?
187
186
@stream . send_headers ( nil , headers )
188
- @stream . send_body ( response . body )
187
+ @stream . send_body ( body )
189
188
else
190
- headers = ::Protocol ::HTTP ::Headers ::Merged . new ( [
191
- [ STATUS , response . status ] ,
192
- ] , response . headers )
189
+ # Ensure the response body is closed if we are ending the stream:
190
+ response . close
193
191
194
192
@stream . send_headers ( nil , headers , ::Protocol ::HTTP2 ::END_STREAM )
195
-
196
- # If the response had a body but it was not sent, close it (e.g. HEAD request).
197
- response . body &.close
198
193
end
199
194
end
200
195
end
0 commit comments