Skip to content

Commit 91148f1

Browse files
committed
WIP
1 parent 6d6fb1a commit 91148f1

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def read
3232
end
3333

3434
def close(error = nil)
35+
super
36+
3537
unless @closed.resolved?
3638
@error = error
3739
@closed.value = true
3840
end
39-
40-
super
4141
end
4242

4343
def wait(persistent = true)

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,37 +90,41 @@ def each(task: Task.current)
9090
# 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:
9191
write_response(@version, 101, response.headers)
9292

93-
stream = write_upgrade_body(protocol)
94-
9593
# At this point, the request body is hijacked, so we don't want to call #finish below.
9694
request = nil
9795
response = nil
9896

99-
# In the case of streaming, `finishable` should wrap a `Remainder` body, which we can safely discard later on.
100-
body.call(stream)
97+
if body.stream?
98+
return body.call(write_upgrade_body(protocol))
99+
else
100+
write_upgrade_body(protocol, body)
101+
end
101102
elsif response.status == 101
102103
# 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.
103104
write_response(@version, response.status, response.headers)
104105

105-
stream = write_tunnel_body(version)
106-
107106
# Same as above:
108107
request = nil
109108
response = nil
110109

111-
body&.call(stream)
110+
if body.stream?
111+
return body.call(write_tunnel_body(version))
112+
else
113+
write_tunnel_body(version, body)
114+
end
112115
else
113116
write_response(@version, response.status, response.headers)
114117

115118
if request.connect? and response.success?
116-
stream = write_tunnel_body(version)
117-
118119
# Same as above:
119120
request = nil
120121
response = nil
121122

122-
# We must return here as no further request processing can be done:
123-
return body.call(stream)
123+
if body.stream?
124+
return body.call(write_tunnel_body(version))
125+
else
126+
write_tunnel_body(version, body)
127+
end
124128
else
125129
head = request.head?
126130

lib/async/http/protocol/http2/input.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def read
3737

3838
return chunk
3939
end
40+
41+
def close(error = nil)
42+
super
43+
44+
if stream = @stream
45+
@stream = nil
46+
stream.finish_input(error)
47+
end
48+
end
4049
end
4150
end
4251
end

lib/async/http/protocol/http2/stream.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def send_body(body, trailer = nil)
123123

124124
# Called when the output terminates normally.
125125
def finish_output(error = nil)
126+
return if self.closed?
127+
126128
trailer = @output&.trailer
127129

128130
@output = nil
@@ -152,14 +154,14 @@ def window_updated(size)
152154
def closed(error)
153155
super
154156

155-
if @input
156-
@input.close_write(error)
157+
if input = @input
157158
@input = nil
159+
input.close_write(error)
158160
end
159161

160-
if @output
161-
@output.stop(error)
162+
if output = @output
162163
@output = nil
164+
output.stop(error)
163165
end
164166

165167
if pool = @pool and @connection

0 commit comments

Comments
 (0)