Skip to content

Commit aa6d0fd

Browse files
Map HTTP/2 body internal errors
1 parent b6bf5b6 commit aa6d0fd

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎lib/async/http/protocol/http2/input.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Copyright, 2020-2026, by Samuel Williams.
55

66
require "protocol/http/body/writable"
7+
require "protocol/http/error"
8+
require "protocol/http2/error"
79

810
module Async
911
module HTTP
@@ -41,6 +43,12 @@ def read
4143
end
4244

4345
return chunk
46+
rescue ::Protocol::HTTP2::StreamError => error
47+
if error.code == ::Protocol::HTTP2::Error::INTERNAL_ERROR
48+
raise ::Protocol::HTTP::RemoteError, error.message
49+
end
50+
51+
raise
4452
end
4553

4654
# 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.

‎test/async/http/protocol/http2/connection_close_with_active_streams.rb‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@
8383
end.wait
8484
end
8585

86+
it "maps a remote internal error while reading the response body" do
87+
Async do |task|
88+
client_connection = Async::HTTP::Protocol::HTTP2::Client.new(client_stream)
89+
client_connection.open!
90+
91+
response = client_connection.create_response
92+
request = Protocol::HTTP::Request.new("https", "example.com", "GET", "/")
93+
client_connection.write_request(response, request)
94+
response.stream.receive_initial_headers([[":status", "200"]], false)
95+
96+
client_connection.read_response(response)
97+
response.stream.close!(Protocol::HTTP2::INTERNAL_ERROR)
98+
99+
expect do
100+
response.body.read
101+
end.to raise_exception(Protocol::HTTP::RemoteError).and(
102+
have_attributes(
103+
cause: be_a(Protocol::HTTP2::StreamError).and(
104+
have_attributes(code: be == Protocol::HTTP2::INTERNAL_ERROR)
105+
)
106+
)
107+
)
108+
end.wait
109+
end
110+
86111
it "does not raise error when connection closes without active streams" do
87112
Async do |task|
88113
# Create client connection

0 commit comments

Comments
 (0)