NAME

Linux::Event::HTTP::Response - HTTP response message

SYNOPSIS

my $res = Linux::Event::HTTP::Response->new(
    status => 200,
    headers => [
        [ 'Content-Type', 'text/plain' ],
    ],
    body => "hello\n",
);

Server callbacks receive the same class:

on_request => sub ($conn, $req, $res) {
    $res->status(200);
    $res->body("hello\n");
};

DESCRIPTION

Linux::Event::HTTP::Response represents one HTTP response message.

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

A Response contains message data only. It is not a socket, Transaction, connection, or writable transport.

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

Incoming client bodies are streaming-first. body contains received body data only when bounded buffering was requested explicitly.

CONSTRUCTOR

my $res = Linux::Event::HTTP::Response->new(
    status  => 200,
    reason  => 'OK',
    version => '1.1',
    headers => [ ... ],
    body    => $bytes,
);

status defaults to 200 and version defaults to 1.1.

HTTP/2 responses use version 2 and do not serialize an HTTP/1 reason phrase.

METHODS

status

Gets or, while mutable, sets a status from 100 through 599.

reason

Gets or, while mutable, sets the optional HTTP/1 reason phrase.

HTTP/2 does not send a reason phrase.

version

Gets or, while mutable, sets the HTTP version.

Gets the first matching field value.

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

add_header

Adds another header field without removing existing same-name fields.

remove_header

Removes all fields with the supplied case-insensitive name.

header_values

Returns an array reference containing 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.

Setting a scalar body marks that message body complete. It does not itself mean the bytes have already been written to a transport.

For a received client Response, body returns data only when bounded buffer_body handling was requested. Otherwise body bytes remain incremental.

has_buffered_body

True when a complete scalar body is locally available.

is_complete

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

is_mutable

True until protocol commit.

SEE ALSO

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