Skip to content

Commit

Permalink
Slightly improved handling of version in HTTP/1 server.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 13, 2024
1 parent 489c468 commit 1c4b5ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/async/http/protocol/http1/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def each(task: Task.current)

while request = next_request
response = yield(request, self)
version = request.version
body = response&.body

if hijacked?
Expand Down Expand Up @@ -77,7 +78,7 @@ def each(task: Task.current)
# This code path is to support legacy behavior where the response status is set to 101, but the protocol is not upgraded. This may not be a valid use case, but it is supported for compatibility. We expect the response headers to contain the `upgrade` header.
write_response(@version, response.status, response.headers)

stream = write_tunnel_body(request.version)
stream = write_tunnel_body(version)

# Same as above:
request = nil
Expand All @@ -89,7 +90,7 @@ def each(task: Task.current)
write_response(@version, response.status, response.headers)

if request.connect? and response.success?
stream = write_tunnel_body(request.version)
stream = write_tunnel_body(version)

# Same as above:
request = nil
Expand All @@ -99,7 +100,6 @@ def each(task: Task.current)
return body.call(stream)
else
head = request.head?
version = request.version

# Same as above:
request = nil unless request.body
Expand All @@ -114,7 +114,7 @@ def each(task: Task.current)
else
# If the request failed to generate a response, it was an internal server error:
write_response(@version, 500, {})
write_body(request.version, nil)
write_body(version, nil)
end

# Gracefully finish reading the request body if it was not already done so.
Expand Down

0 comments on commit 1c4b5ab

Please sign in to comment.