Unblock-HTTP
view release on metacpan or search on metacpan
lib/Unblock/HTTP/QUIC.pm view on Meta::CPAN
next;
}
next if $record->{http} || $record->{attaching} || !$quic->ready;
local $record->{attaching} = 1;
my $http;
if ($self->{role} eq 'Server') {
$http = $self->{server}->attach_quic(connection => $quic);
} else {
require Unblock::HTTP::_EngineFactory;
$http = Unblock::HTTP::_EngineFactory->create(
'Client', 'h3', quic => $quic, %{ $self->{http3} },
);
$http->start;
}
if ($quic->closed) {
delete $self->{sessions}{$id};
next;
}
$record->{http} = $http;
$self->{on_ready}->($http, $self) if $self->{on_ready};
}
return;
}
1;
__END__
=head1 NAME
Unblock::HTTP::QUIC - Manage HTTP/3 connections above Net::QUIC::Driver
=head1 DESCRIPTION
This is the small, event-loop-neutral HTTP/3 connection manager. It uses
Net::QUIC::Driver for packet processing and timer management. The host
still owns one UDP socket and one replaceable timer. The manager attaches
ready server connections to one reusable Server definition and starts client
sessions when QUIC is ready. It retains each HTTP/3 session until its QUIC
connection closes.
It does not create a UDP socket, negotiate transport addresses, or provide
a general user agent. It does not run an extra packet pump.
=head1 SERVER
use Unblock::HTTP::QUIC;
use Unblock::HTTP::Server;
my $server = Unblock::HTTP::Server->new(
http3 => {},
on_request => sub {
my ($tx, $request) = @_;
$tx->respond(status => 200, body => "hello\n");
},
);
my $http = Unblock::HTTP::QUIC->server(
certificate_file => $cert,
private_key_file => $key,
server => $server,
send => sub { my ($datagram) = @_; ... },
set_timeout => sub { my ($seconds) = @_; ... },
);
$http->start;
Forward UDP and timer events:
$http->receive($bytes, $packed_local, $packed_peer);
$http->timeout;
$http->writable;
No code is required to pull new QUIC connections, check handshake readiness,
or create per-connection HTTP/3 Servers.
=head1 CLIENT
my $http = Unblock::HTTP::QUIC->client(
local => $packed_local,
peer => $packed_peer,
server_name => 'example.test',
send => sub { ... },
set_timeout => sub { ... },
on_ready => sub {
my ($client, $manager) = @_;
$client->request(
method => 'GET', target => '/', scheme => 'https',
authority => 'example.test', on_response => sub { ... },
);
},
);
$http->start;
C<on_ready> fires once per ready QUIC connection. On a server manager it
receives the actual HTTP3 Server engine and the manager. On a client manager
it receives the actual HTTP3 Client engine and manager. The shared
multi-origin Client uses connect_quic instead; this helper remains a low-level
Net::QUIC::Driver convenience.
=head1 METHODS
=head2 start, receive, timeout, writable
Forwarded to Net::QUIC::Driver. C<receive> takes one UDP payload plus
its concrete packed local and remote addresses and optionally ECN.
C<timeout> is called on expiration of the single timer specified by
C<set_timeout>. C<writable> is for recovery after UDP send congestion.
=head2 session, sessions
C<session> returns the ready HTTP client on a client manager, or undef
until its handshake finishes. C<sessions> returns active ready HTTP
engines on the server side and unified sessions on the client side.
=head2 driver
Returns the underlying Net::QUIC::Driver for advanced transport control.
( run in 1.333 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )