Class: Protocol::HTTP3::Stream
- Inherits:
-
Object
- Object
- Protocol::HTTP3::Stream
- Defined in:
- lib/protocol/http3/stream.rb
Overview
A single HTTP/3 request or response body stream.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Instance Method Summary collapse
-
#finish ⇒ Object
Finish the stream after all body chunks have been written.
-
#initialize(connection, stream_id) ⇒ Stream
constructor
Initialize the stream wrapper for the given connection and native stream identifier.
-
#read_chunk ⇒ Object
Read the next available body chunk from the stream.
-
#reset(error_code = nil) ⇒ Object
Reset the stream with the optional HTTP/3 error code.
-
#write_body(body) ⇒ Object
Write all chunks from the given body to the stream.
-
#write_chunk(chunk) ⇒ Object
Write a body chunk to the stream.
Constructor Details
#initialize(connection, stream_id) ⇒ Stream
Initialize the stream wrapper for the given connection and native stream identifier.
10 11 12 13 |
# File 'lib/protocol/http3/stream.rb', line 10 def initialize(connection, stream_id) @connection = connection @stream_id = stream_id end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
15 16 17 |
# File 'lib/protocol/http3/stream.rb', line 15 def connection @connection end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
16 17 18 |
# File 'lib/protocol/http3/stream.rb', line 16 def stream_id @stream_id end |
Instance Method Details
#finish ⇒ Object
Finish the stream after all body chunks have been written.
30 31 32 33 |
# File 'lib/protocol/http3/stream.rb', line 30 def finish @connection.__send__(:finish_body, @stream_id) @connection.send_packets end |
#read_chunk ⇒ Object
Read the next available body chunk from the stream.
19 20 21 |
# File 'lib/protocol/http3/stream.rb', line 19 def read_chunk @connection.__send__(:read_body_chunk, @stream_id) end |
#reset(error_code = nil) ⇒ Object
Reset the stream with the optional HTTP/3 error code.
36 37 38 39 |
# File 'lib/protocol/http3/stream.rb', line 36 def reset(error_code = nil) @connection.__send__(:reset_body, @stream_id, error_code) @connection.send_packets end |
#write_body(body) ⇒ Object
Write all chunks from the given body to the stream.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/protocol/http3/stream.rb', line 42 def write_body(body) error = nil begin while chunk = body.read write_chunk(chunk) end rescue => error reset raise ensure body.close(error) finish unless error end end |
#write_chunk(chunk) ⇒ Object
Write a body chunk to the stream.
24 25 26 27 |
# File 'lib/protocol/http3/stream.rb', line 24 def write_chunk(chunk) @connection.__send__(:write_body_chunk, @stream_id, chunk) @connection.send_packets end |