lib/async/http/protocol/http1/server.rb in async-http-0.40.3 vs lib/async/http/protocol/http1/server.rb in async-http-0.41.0
- old
+ new
@@ -64,13 +64,25 @@
unless request.body?
# If there is no body, #finish is a no-op.
request = nil
end
- write_response(@version, response.status, response.headers, response.body, head)
+ write_response(@version, response.status, response.headers)
+
+ if body = response.body and protocol = response.protocol
+ stream = write_upgrade_body(protocol)
+
+ # At this point, the request body is hijacked, so we don't want to call #finish below.
+ request = nil
+
+ body.call(stream)
+ else
+ write_body(@version, body, head)
+ end
else
# If the request failed to generate a response, it was an internal server error:
- write_response(@version, 500, {}, nil)
+ write_response(@version, 500, {})
+ write_body(@version, nil)
end
# Gracefully finish reading the request body if it was not already done so.
request&.finish