File tree Expand file tree Collapse file tree 5 files changed +31
-6
lines changed
test/async/http/middleware Expand file tree Collapse file tree 5 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
spec . add_dependency "async-pool" , "~> 0.7"
29
29
spec . add_dependency "io-endpoint" , "~> 0.11"
30
30
spec . add_dependency "io-stream" , "~> 0.4"
31
- spec . add_dependency "protocol-http" , "~> 0.35 "
32
- spec . add_dependency "protocol-http1" , "~> 0.20 "
31
+ spec . add_dependency "protocol-http" , "~> 0.36 "
32
+ spec . add_dependency "protocol-http1" , "~> 0.23 "
33
33
spec . add_dependency "protocol-http2" , "~> 0.18"
34
34
spec . add_dependency "traces" , ">= 0.10"
35
35
end
Original file line number Diff line number Diff line change 9
9
module Async
10
10
module HTTP
11
11
module Body
12
+ # Keeps track of whether a body is being read, and if so, waits for it to be closed.
12
13
class Finishable < ::Protocol ::HTTP ::Body ::Wrapper
13
14
def initialize ( body )
14
15
super ( body )
15
16
16
17
@closed = Async ::Variable . new
17
18
@error = nil
19
+
20
+ @reading = false
21
+ end
22
+
23
+ def reading?
24
+ @reading
25
+ end
26
+
27
+ def read
28
+ @reading = true
29
+
30
+ super
18
31
end
19
32
20
33
def close ( error = nil )
@@ -27,7 +40,11 @@ def close(error = nil)
27
40
end
28
41
29
42
def wait
30
- @closed . wait
43
+ if @reading
44
+ @closed . wait
45
+ else
46
+ self . discard
47
+ end
31
48
end
32
49
33
50
def inspect
Original file line number Diff line number Diff line change 14
14
require 'traces/provider'
15
15
16
16
require_relative 'protocol'
17
+ require_relative 'body/finishable'
17
18
18
19
module Async
19
20
module HTTP
@@ -140,7 +141,7 @@ def call(request)
140
141
def inspect
141
142
"#<#{ self . class } authority=#{ @authority . inspect } >"
142
143
end
143
-
144
+
144
145
Traces ::Provider ( self ) do
145
146
def call ( request )
146
147
attributes = {
@@ -186,9 +187,14 @@ def call(request)
186
187
def make_response ( request , connection )
187
188
response = request . call ( connection )
188
189
190
+ if body = request . body
191
+ finishable = Body ::Finishable . new ( body )
192
+ end
193
+
189
194
# The connection won't be released until the body is completely read/released.
190
195
::Protocol ::HTTP ::Body ::Completable . wrap ( response ) do
191
196
# TODO: We should probably wait until the request is fully consumed and/or the connection is ready before releasing it back into the pool.
197
+ finishable &.wait
192
198
193
199
# Release the connection back into the pool:
194
200
@pool . release ( connection )
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ def remote_address
33
33
def remote_address = value
34
34
@remote_address = value
35
35
end
36
+
37
+ def finished!
38
+
39
+ end
36
40
end
37
41
end
38
42
end
Original file line number Diff line number Diff line change 18
18
with '301' do
19
19
let ( :app ) do
20
20
Protocol ::HTTP ::Middleware . for do |request |
21
- request . finish # TODO: request.discard - or some default handling?
22
-
23
21
case request . path
24
22
when '/home'
25
23
Protocol ::HTTP ::Response [ 301 , { 'location' => '/' } , [ ] ]
You can’t perform that action at this time.
0 commit comments