NAME
Linux::Event::HTTP::Client - Unblock HTTP client using Linux::Event transports
SYNOPSIS
my $client = Linux::Event::HTTP::Client->new(loop => $loop);
my $op = $client->get('http://localhost:8080/',
timeout => 15,
on_response => sub ($tx, $response) { say $response->body },
);
DESCRIPTION
This thin Unblock::HTTP::Client subclass supplies sockets, deferred work and cancellable Linux::Event timers. Unblock owns pooling, scheduling, operations and transactions. request, pool_stats, pending_count, network_changed and shutdown have the Unblock semantics.
on_response receives a complete bounded response by default. Supplying on_data selects streaming: on_response runs at headers, on_data provides chunks, and on_end signals body completion. on_finish runs at terminal cleanup. timeout is in seconds and includes time in the queue. The returned operation supports cancellation before and after dispatch.
For a streamed upload, set stream_body => 1 and supply on_transaction => sub ($tx) { $tx->write(...); $tx->end }. This callback runs when queued work is admitted to the real engine. It may run synchronously for an available connection; use the supplied Transaction.
Generic H1 request(on_handoff => sub ($tx, $response, $host) { ... }) with explicit http_version => '1.1' transfers a successful 101 Upgrade or CONNECT socket to the consumer returned by the callback. The consumer implements input, EOF, error and output resume. The original socket, TLS and ordered write queue are preserved. The upgraded socket is removed from the HTTP pool, so normal HTTP requests can continue on newly pooled connections. on_finish refers to the HTTP handshake, not the successor's eventual close.
This reconstruction slice supports HTTP/1 over TCP/TLS and optional HTTP/2 over TLS with http2 => 1 (Unblock::HTTP2 0.13 or later). HTTPS verifies the certificate and original hostname by default. tls accepts Linux::Event TLS options such as ca_file. HTTP owns the hostname and ALPN selection. native_input => 0 selects the Perl input path for diagnostics. HTTP/2 uses ALPN and multiplexes operations through Unblock's pool. Ordinary requests can fall back to HTTP/1; http_version => '2' fails if HTTP/2 cannot be negotiated. HTTP/2 on_error may include a third protocol error-code argument. HTTP/3 is optional through http3 => 1 using Net::QUIC 0.06 and Unblock::HTTP3 0.14. quic => { ca_file => ... } configures QUIC-specific trust and transport options. Origin hostnames are resolved asynchronously by Linux::Event UDP, and QUIC authenticates the original HTTPS origin, even when an alternative endpoint is used. Opt-in http1 => { websocket => 1 } enables the inherited connect_websocket() entry point. It transfers the whole HTTP1 socket to the established Unblock::WebSocket session without introducing a second pool; a normal HTTP request can continue on another socket. The same-read native input handoff is verified. Optional http2 => { websocket => 1 } uses multiplexed Extended CONNECT, verified alongside ordinary H2 requests. HTTP3 Extended CONNECT messages and graceful WebSocket Close/FIN are verified by real QUIC loopback, with the completion-recheck fix included in Unblock::HTTP3 0.14. Generic H2/H3 CONNECT uses request(method => 'CONNECT', protocol => 'raw-tunnel', http_version => '2' or '3', on_handoff => sub ($tx, $response, $bridge) { ... }). The callback returns a byte consumer supporting input, input_eof, transport_error and resume_output. $bridge->unblock_send and unblock_finish write/end the stream without closing its TLS/QUIC parent. The Client waits for peer Extended CONNECT SETTINGS automatically; normal H2/H3 sibling HTTP operations continue through the pool. A non-2xx response does not invoke on_handoff; the unused outgoing CONNECT writer is finished and the HTTP response is returned normally. No redirects, cookies, authentication retries or response wrappers are added.