NAME

Net::Blossom::Server::Request - Framework-neutral Blossom server request

SYNOPSIS

use Net::Blossom::Server::Request;

my $request = Net::Blossom::Server::Request->new(
    method  => 'PUT',
    path    => '/upload',
    headers => {
        'Content-Type'   => 'image/png',
        'Content-Length' => 1024,
    },
    body    => $stream,
);

my $type = $request->content_type;

DESCRIPTION

Net::Blossom::Server::Request is the normalized request object used by Net::Blossom::Server. It is intentionally independent of PSGI, PAGI, Plack, and any daemon framework.

Adapters should translate their native request representation into this object before calling the Blossom server core.

CONSTRUCTOR

new

my $request = Net::Blossom::Server::Request->new(%args);

Required arguments:

  • method

    HTTP method. It must be an HTTP token and is normalized to uppercase.

  • path

    Request path. It must start with / and must not contain a query string.

Optional arguments:

  • headers

    Hash reference of HTTP request headers. Header names are case-insensitive and duplicate case-insensitive names croak.

  • query

    Hash reference of query parameters. Values may be scalars or array references of scalars.

  • body

    Request body. It may be a scalar byte string or a stream object that provides read or getline.

  • remote_addr

    Client address as provided by the adapter.

  • content_length

    Content length. Defaults from the Content-Length header when present. It must be a non-negative integer.

  • content_type

    Content type. Defaults from the Content-Type header when present.

Unknown arguments or invalid values croak.

ACCESSORS

method

Returns the uppercase HTTP method.

path

Returns the request path.

body

Returns the scalar body or stream object.

remote_addr

Returns the adapter-provided client address.

content_length

Returns the content length, when known.

content_type

Returns the content type, when known.

METHODS

headers

my $headers = $request->headers;

Returns a copy hash reference of request headers.

my $value = $request->header($name);

Returns a header value using case-insensitive lookup. Returns undef when the header is absent.

query

my $query = $request->query;

Returns a copy hash reference of query parameters. Repeated values are returned as copied array references.

query_param

my $value = $request->query_param($name);

Returns the first query value for $name, or undef when absent.

query_params

my @values = $request->query_params($name);

Returns all query values for $name.

has_body

my $has_body = $request->has_body;

Returns true when the request has a scalar body, a stream body, or a positive content_length.