Skip to content
Closed
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
8 changes: 8 additions & 0 deletions lib/async/http/protocol/http2/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Copyright, 2020-2026, by Samuel Williams.

require "protocol/http/body/writable"
require "protocol/http/error"
require "protocol/http2/error"

module Async
module HTTP
Expand Down Expand Up @@ -41,6 +43,12 @@ def read
end

return chunk
rescue ::Protocol::HTTP2::StreamError => error
if error.code == ::Protocol::HTTP2::Error::INTERNAL_ERROR
raise ::Protocol::HTTP::RemoteError, "Remote endpoint failure while reading the HTTP/2 message body!"
end

raise
end

# Close the application-facing input body and notify the stream that incoming data is no longer being consumed. While local output is active, the HTTP/2 stream remains open. Once output also closes, the remaining wire stream is terminated without an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@
end.wait
end

it "maps a remote internal error while reading the response body" do
Async do |task|
client_connection = Async::HTTP::Protocol::HTTP2::Client.new(client_stream)
client_connection.open!

response = client_connection.create_response
request = Protocol::HTTP::Request.new("https", "example.com", "GET", "/")
client_connection.write_request(response, request)
response.stream.receive_initial_headers([[":status", "200"]], false)

client_connection.read_response(response)
response.stream.close!(Protocol::HTTP2::INTERNAL_ERROR)

expect do
response.body.read
end.to raise_exception(Protocol::HTTP::RemoteError).and(
have_attributes(
cause: be_a(Protocol::HTTP2::StreamError).and(
have_attributes(code: be == Protocol::HTTP2::INTERNAL_ERROR)
)
)
)
end.wait
end

it "does not raise error when connection closes without active streams" do
Async do |task|
# Create client connection
Expand Down
Loading