Skip to content

Commit 9dffa99

Browse files
committed
WIP
1 parent 8523d4f commit 9dffa99

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/async/http/protocol/http1/server.rb

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,37 @@ def each(task: Task.current)
5959
if response
6060
trailer = response.headers.trailer!
6161

62-
write_response(@version, response.status, response.headers)
63-
6462
# Some operations in this method are long running, that is, it's expected that `body.call(stream)` could literally run indefinitely. In order to facilitate garbage collection, we want to nullify as many local variables before calling the streaming body. This ensures that the garbage collection can clean up as much state as possible during the long running operation, so we don't retain objects that are no longer needed.
65-
63+
6664
if body and protocol = response.protocol
65+
# We force a 101 response if the protocol is upgraded - HTTP/2 CONNECT will return 200 for success, but this won't be understood by HTTP/1 clients:
66+
write_response(@version, 101, response.headers)
67+
6768
stream = write_upgrade_body(protocol)
6869

6970
# At this point, the request body is hijacked, so we don't want to call #finish below.
7071
request = response = nil
7172

72-
body.call(stream)
73-
elsif request.connect? and response.success?
74-
stream = write_tunnel_body(request.version)
75-
76-
# Same as above:
77-
request = response = nil
78-
7973
body.call(stream)
8074
else
81-
head = request.head?
82-
version = request.version
83-
84-
# Same as above:
85-
request = nil unless request.body
86-
response = nil
75+
write_response(@version, response.status, response.headers)
8776

88-
write_body(version, body, head, trailer)
77+
if request.connect? and response.success?
78+
stream = write_tunnel_body(request.version)
79+
80+
# Same as above:
81+
request = response = nil
82+
83+
body.call(stream)
84+
else
85+
head = request.head?
86+
version = request.version
87+
88+
# Same as above:
89+
request = response = nil
90+
91+
write_body(version, body, head, trailer)
92+
end
8993
end
9094

9195
# We are done with the body, you shouldn't need to call close on it:

0 commit comments

Comments
 (0)