NAME
Unblock::HTTP2::Transaction - one HTTP/2 request/response transaction
SYNOPSIS
# Inside a Server on_request callback:
my ($tx, $request) = @_;
$tx->send_informational(status => 103);
$tx->respond(status => 200, body => "hello\n");
# Alternatively, to stream a different response:
$tx->respond(status => 200, stream_body => 1);
$tx->write($chunk);
$tx->end($final_chunk);
The second example is an alternative to the first, not a second response on the same Transaction. respond(), send_informational(), and Client request() accept named HTTP fields directly; creating a Uniform message by hand is optional.
DESCRIPTION
A Transaction represents one HTTP request/response exchange carried by one multiplexed HTTP/2 stream.
request() returns the Uniform request. response() returns the Uniform response once one is available.
STREAMING BODIES
For a streaming local body:
$transaction->write($chunk);
$transaction->end($last_chunk);
write() always accepts the bytes. A false return means the cooperative high-water mark was reached, or an attached host has become congested. Wait for on_drain before producing more.
Incoming body bytes are consumed automatically after the body callback returns.
For manual receive flow control:
$transaction->auto_consume(0);
$transaction->consume($bytes_processed);
unconsumed_bytes() reports body bytes still waiting for stream-level credit.
SERVER RESPONSES
A server Transaction can send an informational response with:
$transaction->send_informational(status => 103);
The final response uses:
$transaction->respond(status => 200, body => "hello\n");
Both calls accept a canonical Uniform::HTTP::Response object too.
Pass stream_body => 1 to respond() to produce the response body with write() and end(). on_drain and on_error are response options, not HTTP fields.
RESETS
cancel() sends the standard HTTP/2 CANCEL reset.
reset($error_code) sends an explicit RST_STREAM reason.
The Transaction preserves:
error
error_code
error_name
reset_by_peer
These facts are exposed for higher-level retry and policy decisions.
PRIORITY
Client Transactions can use update_priority($field_value) to send an RFC 9218 PRIORITY_UPDATE after the peer has enabled modern priorities.
STATE
Useful state accessors include:
stream_id
state
is_complete
is_cancelled
is_error
is_terminal
HTTP/2 half-close is preserved. One direction may finish before the full Transaction becomes terminal.
SEE ALSO
Unblock::HTTP2, Unblock::HTTP2::Client, Unblock::HTTP2::Server, Unblock::HTTP2::Integration
LICENSE
MIT License.