NAME
Plack::Response - Portable HTTP Response object for PSGI response
SYNOPSIS
use Plack::Response;
sub psgi_handler {
my $env = shift;
my $res = Plack::Response->new(200);
$res->content_type('text/html');
$res->body("Hello World");
return $res->finalize;
}
DESCRIPTION
Plack::Response allows you a way to create PSGI response array ref through a simple API.
METHODS
- new
-
$res = Plack::Response->new; $res = Plack::Response->new($status); $res = Plack::Response->new($status, $headers); $res = Plack::Response->new($status, $headers, $body);
Creates a new Plack::Response object.
- status
-
$res->status(200); $status = $res->status;
Sets and gets HTTP status code.
code
is an alias. - headers
-
$headers = $res->headers; $res->headers([ 'Content-Type' => 'text/html' ]); $res->headers({ 'Content-Type' => 'text/html' }); $res->headers( HTTP::Headers->new );
Sets and gets HTTP headers of the response. Setter can take either an array ref, a hash ref or HTTP::Headers object containing a list of headers.
- body
-
$res->body($body_str); $res->body([ "Hello", "World" ]); $res->body($io);
Gets and sets HTTP response body. Setter can take either a string, an array ref, or an IO::Handle-like object.
content
is an alias. - header
-
$res->header('X-Foo' => 'bar'); my $val = $res->header('X-Foo');
Shortcut for
$res->headers->header
. - content_type, content_length, content_encoding
-
$res->content_type('text/plain'); $res->content_length(123); $res->content_encoding('gzip');
Shortcut for the equivalent get/set methods in
$res->headers
. - redirect
-
$res->redirect($url); $res->redirect($url, 301);
Sets redirect URL with an optional status code, which defaults to 302.
- location
-
Gets and sets
Location
header. -
$res->cookies->{foo} = { value => '123' };
Returns a hash reference containing cookies to be set in the response. The keys of the hash are the cookies' names, and their corresponding values are hash reference used to construct a CGI::Simple::Cookie object.
AUTHOR
Tokuhiro Matsuno
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.