Skip to content

Avoid writing to the body after full hijack #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion async-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/async/http/protocol/http1/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 29 additions & 1 deletion test/async/http/protocol/http11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def around
"Hello World!"
)
peer.close

nil
end
end
Expand All @@ -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
Loading