NAME
PAGI::Server::Protocol::HTTP1 - HTTP/1.1 protocol handler
SYNOPSIS
use PAGI::Server::Protocol::HTTP1;
my $proto = PAGI::Server::Protocol::HTTP1->new;
# Parse incoming request
my ($request, $consumed) = $proto->parse_request($buffer);
# Serialize response
my $bytes = $proto->serialize_response_start(200, \@headers, $chunked);
$bytes .= $proto->serialize_response_body($chunk, $more);
DESCRIPTION
PAGI::Server::Protocol::HTTP1 isolates HTTP/1.1 wire-format parsing and serialization from PAGI event handling. This allows clean separation of protocol handling and future addition of HTTP/2 or HTTP/3 modules with the same interface.
METHODS
new
my $proto = PAGI::Server::Protocol::HTTP1->new;
Creates a new HTTP1 protocol handler.
parse_request
my ($request_info, $bytes_consumed) = $proto->parse_request($buffer);
Parses an HTTP request from the buffer. Returns undef if the request is incomplete. On success, returns:
$request_info = {
method => 'GET',
path => '/foo',
raw_path => '/foo%20bar',
query_string => 'a=1',
http_version => '1.1',
headers => [ ['host', 'localhost'], ... ],
content_length => 0, # or undef if not present
chunked => 0, # 1 if Transfer-Encoding: chunked
};
serialize_response_start
my $bytes = $proto->serialize_response_start($status, \@headers, $chunked);
Serializes the response line and headers.
serialize_response_body
my $bytes = $proto->serialize_response_body($chunk, $more, $chunked);
Serializes a body chunk. Uses chunked encoding if $chunked is true.
serialize_trailers
my $bytes = $proto->serialize_trailers(\@headers);
Serializes HTTP trailers.
parse_chunked_body
my ($data, $bytes_consumed, $complete) = $proto->parse_chunked_body($buffer);
Parses chunked Transfer-Encoding body from the buffer. Returns: - $data: decoded body data (may be empty string) - $bytes_consumed: number of bytes consumed from buffer - $complete: 1 if final chunk (0-length) was seen, 0 otherwise
Returns (undef, 0, 0) if more data is needed.
SEE ALSO
PAGI::Server::Connection, HTTP::Parser::XS
AUTHOR
John Napiorkowski <jjnapiork@cpan.org>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.