NAME

Linux::Event::HTTP::Request - HTTP request message

SYNOPSIS

my $req = Linux::Event::HTTP::Request->new(
    method => 'POST',
    target => '/items',
    headers => [
        [ 'Content-Type', 'application/json' ],
    ],
    body => $bytes,
);

DESCRIPTION

Linux::Event::HTTP::Request represents one HTTP request message.

The same class is used for HTTP/1 and HTTP/2, and for both locally constructed outgoing requests and received incoming requests.

A Request contains message data only: method, request target, HTTP version, headers, optional scheme/authority metadata, and an optional complete scalar body. It does not own the socket, connection, Transaction, streaming producer, redirect policy, or authentication policy.

Locally constructed Requests are mutable until protocol commit. Received Requests are read-only.

Incoming bodies are streaming-first and are not accumulated into the Request automatically.

CONSTRUCTOR

my $req = Linux::Event::HTTP::Request->new(
    method    => 'GET',
    target    => '/',
    version   => '1.1',
    scheme    => 'https',
    authority => 'example.com',
    headers   => [ ... ],
    body      => $bytes,
);

method and target are required. version defaults to 1.1.

headers is an array reference of [name, value] pairs. Duplicates, field order, and original field-name spelling are preserved.

METHODS

method

Gets or, while mutable, sets the HTTP method.

target

Gets or, while mutable, sets the exact request target.

target_is_exact

Returns true. The request target is preserved rather than reconstructed from routing state.

version

Gets or, while mutable, sets the HTTP version, such as 1.1 or 2.

scheme

Gets or sets protocol-neutral request scheme metadata while mutable.

HTTP/2 maps :scheme here. HTTP/1 absolute-form requests can also provide it. Origin-form HTTP/1 requests normally have no scheme in the message itself.

authority

Gets or sets protocol-neutral authority metadata while mutable.

HTTP/2 maps :authority here. HTTP/1 may derive authority from absolute-form, CONNECT authority-form, or one unambiguous Host field.

HTTP/2 pseudo-headers never appear in the ordinary header list.

my $value = $req->header('Host');
$req->header('Accept', 'application/json');

Returns the first matching value.

On a mutable Request, the setter replaces all fields of the same case-insensitive name with one field.

add_header

Adds another field without removing existing same-name fields.

remove_header

Removes all fields with the supplied case-insensitive name.

header_values

Returns an array reference of all matching values in message order.

header_count, header_name, header_value

Provide exact indexed access to the lossless header list.

headers_are_lossless

Returns true.

content_length

Returns the declared Content-Length as an integer, or undef when absent.

body

Gets or, while mutable, sets a complete scalar body.

This is not the streaming-body API. Incremental outgoing bodies belong to the Transaction, and incoming bodies are delivered by the protocol layer.

has_buffered_body

True when a complete scalar body is locally available, including an explicit empty body.

is_complete

True when the complete message body boundary is known or has been reached.

is_mutable

True only while a locally constructed Request remains uncommitted.

SEE ALSO

Linux::Event::HTTP::Response, Linux::Event::HTTP::Transaction, Linux::Event::HTTP::Client, Linux::Event::HTTP::Server.