diff --git a/async-http.gemspec b/async-http.gemspec index 5247d9c5..7bd0bcd7 100644 --- a/async-http.gemspec +++ b/async-http.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.add_dependency "async-io", ">= 1.28" spec.add_dependency "async-pool", ">= 0.2" spec.add_dependency "protocol-http", "~> 0.26.0" - spec.add_dependency "protocol-http1", "~> 0.18.0" + spec.add_dependency "protocol-http1", "~> 0.19.0" spec.add_dependency "protocol-http2", "~> 0.16.0" spec.add_dependency "traces", ">= 0.10.0" end diff --git a/lib/async/http/protocol/http1/server.rb b/lib/async/http/protocol/http1/server.rb index 901d25c3..79bc2486 100644 --- a/lib/async/http/protocol/http1/server.rb +++ b/lib/async/http/protocol/http1/server.rb @@ -50,8 +50,8 @@ def each(task: Task.current) response = yield(request, self) body = response&.body - if @stream.nil? and body.nil? - # Full hijack. + if hijacked? + body&.close return end diff --git a/test/async/http/protocol/http11.rb b/test/async/http/protocol/http11.rb index 67448c2a..ab36016c 100755 --- a/test/async/http/protocol/http11.rb +++ b/test/async/http/protocol/http11.rb @@ -65,7 +65,7 @@ def around "Hello World!" ) peer.close - + nil end end @@ -82,5 +82,33 @@ def around expect(response.reason).to be == "It worked!" end end + + with 'full hijack with empty response' do + let(:body) {Async::HTTP::Body::Buffered.new([], 0)} + + let(:app) do + ::Protocol::HTTP::Middleware.for do |request| + peer = request.hijack! + + peer.write( + "#{request.version} 200 It worked!\r\n" + + "connection: close\r\n" + + "\r\n" + + "Hello World!" + ) + peer.close + + ::Protocol::HTTP::Response[-1, {}, body] + end + end + + it "works properly" do + expect(body).to receive(:close) + + response = client.get("/") + + expect(response.read).to be == "Hello World!" + end + end end end