NAME
Nile::Response - The HTTP response manager.
SYNOPSIS
# get response instance
$res = $app->response;
$res->code(200);
$res->content_type('text/html');
$res->body("Hello World");
$response = $res->response;
# [$code, $headers, $body]
DESCRIPTION
Nile::Response - The HTTP response manager allows you to create PSGI response array ref.
- 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.
- header
-
$res->header('X-Foo' => 'bar'); my $val = $res->header('X-Foo');
Sets and gets HTTP header of the response.
- status
-
$res->status(200); $status = $res->status;
Sets and gets HTTP status code.
code
is an alias. - 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.Note that this method doesn't automatically set Content-Length for the response. You have to set it manually if you want, with the
content_length
method. -
$res->cookies->{name} = 123; $res->cookies->{name} = {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 a plain string (for
value
with everything else defaults) or a hash reference that can contain keys such asvalue
,domain
,expires
,path
,httponly
,secure
,max-age
.expires
can take a string or an integer (as an epoch time) and does not convert string formats such as+3M
.$res->cookies->{name} = { value => 'test', path => "/", domain => '.example.com', expires => time + 24 * 60 * 60, };
- content_length
-
$res->content_length(123);
A decimal number indicating the size in bytes of the message content. Shortcut for the equivalent get/set method in
$res->headers
. - content_type
-
$res->content_type('text/plain');
The Content-Type header field indicates the media type of the message content. Shortcut for the equivalent get/set method in
$res->headers
. - content_encoding
-
$res->content_encoding('gzip');
Shortcut for the equivalent get/set method in
$res->headers
. - location
-
Gets and sets
Location
header.Note that this method doesn't normalize the given URI string in the setter.
- redirect
-
$res->redirect($url); $res->redirect($url, 301);
Sets redirect URL with an optional status code, which defaults to 302.
Note that this method doesn't normalize the given URI string. Users of this module have to be responsible about properly encoding URI paths and parameters.
- response
-
$res->response; # [$code, \@headers, $body]
Returns the status code, headers, and body of this response as a PSGI response array reference.
- to_app
-
$app = $res->to_app;
A helper shortcut for
sub { $res->response }
.
Bugs
This project is available on github at https://github.com/mewsoft/Nile.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Nile.
SOURCE
Source repository is at https://github.com/mewsoft/Nile.
ACKNOWLEDGMENT
This module is based on Plack::Response
SEE ALSO
See Nile for details about the complete framework.
AUTHOR
Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> Website: http://www.mewsoft.com
COPYRIGHT AND LICENSE
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, https://github.com/mewsoft/Nile, http://www.mewsoft.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 52:
'=item' outside of any '=over'
- Around line 393:
You forgot a '=back' before '=head1'