NAME

Unblock::HTTP1::Server - Standalone HTTP/1 server protocol engine

SYNOPSIS

use Uniform::HTTP::Response;
use Unblock::HTTP1::Server;

my $server = Unblock::HTTP1::Server->new(
    on_request => sub {
        my ($tx, $request) = @_;
        $tx->respond(Uniform::HTTP::Response->new(
            status => 200,
            body   => "hello\n",
        ));
    },
);

DESCRIPTION

This object owns one HTTP/1 server connection's protocol state. It does not create a listener, socket, TLS session, or event loop.

Incoming request bodies are delivered with on_body. on_request_end runs after the full request, including trailers, is complete. Informational responses can be sent with send_informational() on the Transaction.

CALLBACKS

new() accepts these callbacks:

on_request     => sub { my ($transaction, $request) = @_ }
on_body        => sub { my ($transaction, $request, $bytes) = @_ }
on_request_end => sub { my ($transaction, $request) = @_ }
on_error       => sub { my ($transaction, $error) = @_ }
on_switch      => sub { my ($transaction, $response) = @_ }

on_request is required.

A 101 response or successful CONNECT switches the engine out of HTTP mode. Bytes already read after the HTTP request are preserved by take_remainder().