NAME

Uniform::HTTP::Response - Framework-neutral HTTP response

SYNOPSIS

use Uniform::HTTP::Response;

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

DESCRIPTION

Uniform::HTTP::Response represents HTTP response data without sending a response or owning a connection, transaction, framework, or event loop.

A response always has a status. It may also carry a reason phrase, version, headers, trailers, and a buffered body.

CONSTRUCTOR

new

my $response = Uniform::HTTP::Response->new(
    status => 200,
    body   => 'ok',
);

status is required.

Optional arguments are:

  • reason

  • version

  • headers

  • trailers

  • body

METHODS

status

my $status = $response->status;

Returns the HTTP status code.

Set it with:

$response->status(404);

Valid status values are integers from 100 through 599.

reason

my $reason = $response->reason;

Returns the reason phrase, or undef when none was supplied.

Set or clear it with:

$response->reason('Not Found');
$response->reason(undef);

Uniform does not invent standard reason phrases such as OK.

INFORMATIONAL RESPONSES

A status from 100 through 199 uses a normal Response object:

my $hints = Uniform::HTTP::Response->new(
    status => 103,
    headers => [ [ 'Link', '</style.css>; rel=preload' ] ],
);

Each informational and final response is a separate object. A complete informational message does not mean its exchange is finished. The HTTP implementation owns ordering and rules such as whether 101 or a body is allowed in the selected protocol and request context.

Status and reason setters are blocked by freeze_initial() and freeze(). Received HTTP/2 and HTTP/3 responses normally have no reason phrase. Application-created responses may leave version unset for the sender to choose independently.

INHERITED METHODS

Headers, trailers, bodies, versions, section mutability, and completeness come from Uniform::HTTP::Message.

SEE ALSO

Uniform::HTTP, Uniform::HTTP::Message, Uniform::HTTP::Request.

AUTHOR

Joshua S. Day <HAX@cpan.org>

LICENSE

This software is available under the MIT License.