Skip to content

Commit 78206b8

Browse files
committed
Prefer Protocol::HTTP::Body::Stream.
1 parent 729e26d commit 78206b8

File tree

4 files changed

+13
-187
lines changed

4 files changed

+13
-187
lines changed

Diff for: async-http.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
2020
spec.add_dependency "async", ">= 1.25"
2121
spec.add_dependency "async-io", ">= 1.28"
2222
spec.add_dependency "async-pool", ">= 0.2"
23-
spec.add_dependency "protocol-http", "~> 0.22.0"
23+
spec.add_dependency "protocol-http", "~> 0.22.9"
2424
spec.add_dependency "protocol-http1", "~> 0.14.0"
2525
spec.add_dependency "protocol-http2", "~> 0.14.0"
2626
spec.add_dependency "traces", "~> 0.4.0"

Diff for: lib/async/http/body/hijack.rb

+10-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
# THE SOFTWARE.
2222

2323
require 'protocol/http/body/readable'
24-
require_relative 'stream'
24+
require 'protocol/http/body/stream'
25+
26+
require_relative 'writable'
2527

2628
module Async
2729
module HTTP
@@ -42,6 +44,7 @@ def initialize(block, input = nil)
4244

4345
@task = nil
4446
@stream = nil
47+
@output = nil
4548
end
4649

4750
# We prefer streaming directly as it's the lowest overhead.
@@ -57,23 +60,18 @@ def call(stream)
5760

5861
# Has the producer called #finish and has the reader consumed the nil token?
5962
def empty?
60-
if @stream
61-
@stream.empty?
62-
else
63-
false
64-
end
63+
@output&.empty?
6564
end
6665

6766
def ready?
68-
if @stream
69-
@stream.output.ready?
70-
end
67+
@output&.ready?
7168
end
7269

7370
# Read the next available chunk.
7471
def read
75-
unless @task
76-
@stream = Stream.new(@input)
72+
unless @output
73+
@output = Writable.new
74+
@stream = ::Protocol::HTTP::Body::Stream.new(@input, @output)
7775

7876
@task = Task.current.async do |task|
7977
task.annotate "Streaming hijacked body."
@@ -82,7 +80,7 @@ def read
8280
end
8381
end
8482

85-
return @stream.output.read
83+
return @output.read
8684
end
8785

8886
def inspect

Diff for: lib/async/http/body/stream.rb

-172
This file was deleted.

Diff for: lib/async/http/protocol/http2/output.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23-
require_relative '../../body/stream'
23+
require 'protocol/http/body/stream'
2424

2525
module Async
2626
module HTTP
@@ -88,7 +88,7 @@ def stream(task)
8888

8989
input = @stream.wait_for_input
9090

91-
@body.call(Body::Stream.new(input, self))
91+
@body.call(::Protocol::HTTP::Body::Stream.new(input, self))
9292
rescue Async::Stop
9393
# Ignore.
9494
end

0 commit comments

Comments
 (0)