Prancer::Response(3)

NAME
Prancer::Response

SYNOPSIS
    sub handle {

        ...

        my $response = context->response();
        status(Prancer::Const::OK);
        response->header("Content-Type" => "text/plain");
        response->body("hello, goodbye");
        finalize;
    }

    # or using a callback
    sub handle {

        ...

        status(Prancer::Const::OK);
        $response->header("Content-Type" => "text/plain");
        $response->callback(sub {
            my $writer = shift;
            $writer->write("What's up?");
            $writer->close();
        });
        finalize;
    }

ATTRIBUTES

header
    If called with no arguments this will return the names of all headers that have been set to be sent with the response. Otherwise, this method expects a list of headers to add to the response. For example:

        $response->header("Content-Type" => "text/plain");
        $response->header("Content-Length" => 1234, "X-Foo" => "bar");

    If the header has already been set this will add another value to it and the response will include the same header multiple times. To replace a header that has already been set, remove the existing value first:

        $response->headers->remove("X-Foo");

headers
    Returns a Hash::MultiValue of all headers that have been set to be sent with the response.

cookie
    If called with no arguments this will return the names of all cookes that have been set to be sent with the response. Otherwise, this method expects a list of cookies to add to the response. For example:

        $response->cookie('foo' => {
            'value'   => 'test',
            'path'    => "/",
            'domain'  => '.example.com',
            'expires' => time + 24 * 60 * 60,
        });

    The hashref may contain things such as "value", "domain", "expires", "path", "httponly", and "secure". "expires" can take a string or an integer (as an epoch time) and does not convert string formats like "+3M".

cookies
    Returns a Hash::MultiValue of all cookies that have been set to be sent with the response.

body
    Send buffered output to the client. Anything sent to the client with this method will be buffered until "finalize" is called. For example:

        $response->body("hello");
        $response->body("goodbye", "world");

    The body may also be a callback to send a streaming response to the client. Any headers or response codes set in the callback will be ignored as they must all be set beforehand. Any body set before or after a callback is set will also be ignored. For example:

        $response->body(sub {
            my $writer = shift;
            $writer->write("Hello, world!");
            $writer->close();
        });

finalize
    This requires one argument: the HTTP status code of the response. It will then send a PSGI compatible result. For example:

        # send a 200 response
        $response->finalize(Prancer::Const::OK);

        # or hard code it
        $response->finalize(405);