Unblock-HTTP

 view release on metacpan or  search on metacpan

lib/Unblock/HTTP/Integration.pm  view on Meta::CPAN

        transport => $self,
        alpn => $negotiated_alpn,
    );

The adapter passes decrypted bytes directly to that engine. There is no
Server-definition call on the read path:

    $self->{http}->input($bytes);
    $self->{http}->input_eof;
    $self->{http}->transport_error($error);

Call C<input_eof> once when the peer's read side ends. The framework must not
continue feeding a closed engine. Constructor and attachment errors belong
to adapter setup; handle them before accepting further traffic.

For cleartext H2 prior knowledge, use C<protocol =E<gt> 'h2'> instead of
C<alpn>. Missing or empty ALPN selects H1 only when enabled. Unknown or
disallowed negotiation results fail. The selector does not sniff input bytes.

=head1 OUTPUT CONTRACT

The attached transport implements:

    unblock_send($bytes)
    unblock_finish()
    unblock_abort($reason)

C<unblock_send> accepts the entire buffer or throws. True or undef means it
can accept more output. A defined false value means it accepted every byte
but is congested. It must retain any bytes not yet written by the socket.
False never means partial acceptance, and the engine must not resend the
accepted buffer. When capacity returns, call:

    $self->{http}->resume_output;

C<unblock_finish> asks the framework to flush accepted output and then finish
normally. C<unblock_abort> reports failure and requests immediate teardown.
Do not implement another independent network queue in Unblock::HTTP.

The engine holds the transport weakly. The framework must retain both the
transport and its engine. The reusable Server does not retain attached
engines. Callbacks shared by a Server definition should not capture every
connection or create ownership cycles.

=head1 HTTP/3

Use a ready QUIC connection already negotiated for HTTP/3:

    my $engine = $server->attach_quic(connection => $ready_h3_connection);

The returned HTTP3 Server is already started. Keep it alive while the QUIC
connection is active. This attachment method does not negotiate ALPN; the
caller supplies an H3 connection. UDP packets never go to HTTP C<input>.

L<Unblock::HTTP::QUIC> can manage readiness and engine lifetime for all
connections on a server Driver:

    my $endpoint = Unblock::HTTP::QUIC->server(
        server => $server,
        certificate_file => $cert,
        private_key_file => $key,
        send => $send_datagram,
        set_timeout => $replace_timer,
    );
    $endpoint->start;

Forward UDP receive events to C<receive>, timer expiry to C<timeout>, and
recovered UDP capacity to C<writable>. Net::QUIC::Driver determines the next
timeout in seconds; the framework replaces its timer accordingly. The manager
sets H3 ALPN and uses the supplied reusable Server definition without overriding
its callbacks or policy. C<on_ready> receives the real HTTP3 Server engine.

=head1 SHARED CLIENT FACTORIES

The shared Client requires framework callbacks for connection establishment:

    my $client = Unblock::HTTP::Client->new(
        http1 => {}, http2 => {}, http3 => {},
        connect_stream => sub {
            my ($origin, $alpn_choices, $ready) = @_;
            # Use the framework to establish TCP/TLS.
            # In its connection callback:
            # my $engine = $ready->(
            #     transport => $framework_stream, alpn => $negotiated,
            # );
            # $framework_stream->{http_engine} = $engine;
        },
        connect_quic => sub {
            my ($origin, $ready) = @_;
            # Establish QUIC with the framework/Net::QUIC::Driver.
            # my $engine = $ready->(connection => $ready_quic);
        },
        defer => sub {
            my ($callback) = @_;
            # Schedule for a LATER event-loop turn, never inline.
        },
    );

The ready callback returns the actual H1, H2, or H3 Client engine after
successful attachment, so the framework can retain it. Every new
connect_stream invocation requires its OWN connected byte transport;
it must not attach a second HTTP engine to an already-owned socket. Feed TCP bytes,
EOF, errors and recovered output capacity directly to that engine. For
HTTP/3, preserve QUIC Driver UDP and timer operation and let HTTP/3 own
its stream callbacks. The pooled Client is not a byte-path forwarding object.

The TCP factory may report C<verified_origin =E<gt> 1> ONLY after
successfully validating the HTTPS TLS certificate against the original
origin hostname. This enables learning Alt-Svc from that connection.
The QUIC factory receives C<alternative_host> and C<alternative_port>
when an advertised alternative is selected, while retaining the original
origin authority and host. It MUST authenticate the QUIC peer for the
original HTTPS origin and report C<verified_origin =E<gt> 1> for the
request to be dispatched. A missing attestation rejects that alternative.

The framework should call C<$client-E<gt>network_changed> after a
meaningful route/interface/VPN transition. This explicitly clears
old Alt-Svc hints and idle sockets. Active requests retain their
transactions and finish or fail naturally without blind replay.
Connection factories that were still pending are abandoned safely.
C<$client-E<gt>pool_stats> exposes read-only counts for adapter



( run in 0.800 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )