lib/async/http/protocol/http1/server.rb in async-http-0.47.0 vs lib/async/http/protocol/http1/server.rb in async-http-0.48.0

- old
+ new

@@ -35,11 +35,11 @@ return unless @persistent # Read an incoming request: return unless request = Request.read(self) - unless persistent?(request.version, request.headers) + unless persistent?(request.version, request.method, request.headers) @persistent = false end return request rescue Async::TimeoutError @@ -56,18 +56,10 @@ response = yield(request, self) return if @stream.nil? or @stream.closed? if response - # Try to avoid holding on to request, to minimse GC overhead: - head = request.head? - - unless request.body? - # If there is no body, #finish is a no-op. - request = nil - end - write_response(@version, response.status, response.headers) body = response.body if body and protocol = response.protocol @@ -78,10 +70,23 @@ # We also don't want to hold on to the response object: response = nil body.call(stream) + elsif body and request.connect? + stream = write_tunnel_body(request.version) + + # Same as above: + request = nil + response = nil + + body.call(stream) else + head = request.head? + + request = nil unless body + response = nil + 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, {})