NAME
Linux::Event::HTTP::Request - HTTP request message
SYNOPSIS
my $request = 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 locally constructed outgoing requests and parsed incoming requests.
Locally constructed requests are mutable until the HTTP transaction commits them for transmission. Parsed incoming requests expose committed, read-only metadata. HTTP/1 parser state remains native and lazy: method, target, and header strings are materialized as Perl scalars only when requested.
The public message API conforms directly to the Uniform::HTTP 0.02 message contract by behavior; it does not inherit from a Uniform class. Duplicate header occurrences, inter-field order, original field-name spelling, and the exact request-target are preserved. Connection, Transaction, streaming, retry, and protocol-handoff state remain outside the Request.
The Request does not own a socket or a transaction. Incremental body transfer belongs to the transaction/connection layer. body is only the convenience representation for a complete scalar body; incoming bodies are not implicitly buffered into the Request object.
METHODS
new
Constructs a mutable request message. method and target are required. version defaults to 1.1. headers is an optional array reference of [name, value] pairs so duplicates and field order are preserved. body is an optional complete scalar byte body.
method
Gets the request method. A locally constructed request may set it before the message is committed.
target
Gets the request target exactly as it appears in the HTTP message. A locally constructed request may set it before commit.
target_is_exact
Returns true. Linux::Event::HTTP preserves the exact Request target rather than reconstructing it from decomposed URL or routing state.
version
Gets the HTTP version, such as 1.1. A locally constructed request may set it before commit. Passing undef clears the represented version; an HTTP/1 executor will reject an unset version when transmission is attempted.
header
my $host = $request->header('Host');
$request->header('Accept', 'application/json');
Returns the first matching field value. On a mutable local Request, the setter form replaces all fields of the same ASCII case-insensitive name with one field at the position of the first occurrence, or appends it when absent.
add_header
Adds another header field while preserving existing same-name fields.
remove_header
Removes all fields with the supplied ASCII case-insensitive name.
header_values
Returns an array reference containing all matching values in message order. An absent field returns an empty array reference. Values are never implicitly comma-joined.
header_count, header_name, header_value
Provide exact indexed access to fields in message order while preserving the original field names. A non-negative index beyond the end returns undef; negative and non-integer indexes are programmer errors.
headers_are_lossless
Returns true because duplicate occurrences, inter-field order, and original field-name spelling are retained.
content_length
Returns the declared Content-Length as an integer, or undef when absent. Parsed HTTP/1 requests have already had conflicting values rejected.
body
Gets or sets the complete scalar byte body of a locally constructed Request. Incremental outgoing bodies are selected through the owning Transaction rather than through the Request message. Incoming bodies are delivered incrementally by the transaction/connection layer and are not implicitly accumulated here. Passing undef as a body is an error; an explicit empty body is ''.
has_buffered_body
Returns true only when a complete scalar body buffer is locally available, including an explicit empty buffer. Parsed incoming Request bodies are streamed by the surrounding protocol layer and therefore return false.
is_complete
Returns whether the complete message body boundary has been reached. A locally constructed scalar-body request is complete immediately; an outgoing or incoming streamed request becomes complete only when the protocol layer reaches its final body boundary.
is_mutable
Returns true only while a locally constructed Request has not been committed for transmission. Parsed incoming Requests are read-only and return false.