PAGI
view release on metacpan or search on metacpan
lib/PAGI/Server/Protocol/HTTP2.pm view on Meta::CPAN
my $consumed = $session->feed($data);
Feed incoming data to the HTTP/2 session. Returns bytes consumed.
=cut
sub feed {
my ($self, $data) = @_;
return $self->{nghttp2}->mem_recv($data);
}
=head2 extract
my $data = $session->extract;
Extract outgoing data from the session. Returns bytes to send.
=cut
sub extract {
my ($self) = @_;
return $self->{nghttp2}->mem_send;
}
=head2 want_read
if ($session->want_read) { ... }
Check if session wants to read.
=cut
sub want_read {
my ($self) = @_;
return $self->{nghttp2}->want_read;
}
=head2 want_write
if ($session->want_write) { ... }
Check if session has data to write.
=cut
sub want_write {
my ($self) = @_;
return $self->{nghttp2}->want_write;
}
=head2 submit_response
$session->submit_response($stream_id,
status => 200,
headers => [['content-type', 'text/html']],
body => $body,
);
Submit a response on a stream. C<body> can be a string (sent as single
response) or a coderef for streaming.
=cut
sub submit_response {
my ($self, $stream_id, %args) = @_;
return $self->{nghttp2}->submit_response($stream_id, %args);
}
=head2 submit_response_streaming
$session->submit_response_streaming($stream_id,
status => 200,
headers => [['content-type', 'text/event-stream']],
data_callback => sub {
my ($stream_id, $max_len) = @_;
return ($chunk, $is_eof);
},
);
Submit a streaming response with a data provider callback.
=cut
sub submit_response_streaming {
my ($self, $stream_id, %args) = @_;
return $self->{nghttp2}->submit_response($stream_id,
status => $args{status},
headers => $args{headers},
data_callback => $args{data_callback},
callback_data => $args{callback_data},
);
}
=head2 resume_stream
$session->resume_stream($stream_id);
Resume a deferred stream after data becomes available.
=cut
sub resume_stream {
my ($self, $stream_id) = @_;
return $self->{nghttp2}->resume_stream($stream_id);
}
=head2 submit_data
$session->submit_data($stream_id, $data, $eof);
Push data directly onto a stream. Used for WebSocket frame delivery
over HTTP/2 where frames are sent as DATA payloads.
=cut
sub submit_data {
my ($self, $stream_id, $data, $eof) = @_;
return $self->{nghttp2}->submit_data($stream_id, $data, $eof);
}
=head2 terminate
$session->terminate($error_code);
Terminate the session with GOAWAY.
=cut
sub terminate {
my ($self, $error_code) = @_;
$error_code //= 0; # NO_ERROR
return $self->{nghttp2}->terminate_session($error_code);
}
1;
__END__
=head1 HTTP/2 vs HTTP/1.1
Key differences that affect PAGI integration:
=over 4
=item * Multiplexing - Multiple concurrent requests on one TCP connection
=item * Binary Framing - nghttp2 handles all framing; PAGI feeds/extracts bytes
=item * Header Compression - HPACK is built into nghttp2
=item * Flow Control - Per-stream and connection-level, via streaming callbacks
=back
=head1 SEE ALSO
L<Net::HTTP2::nghttp2>, L<PAGI::Server::Protocol::HTTP1>
=cut
( run in 0.753 second using v1.01-cache-2.11-cpan-140bd7fdf52 )