NAME
Egg::Response - HTTP response processing for Egg.
SYNOPSIS
# The response object is obtained.
my $res= $e->response;
# An original response header is set.
$res->headers->header( 'X-ORIGN' => 'OK' );
# Set Cookie is setup.
$res->cookie( new_cookie => 'set_value' );
or
$res->cookies->{new_cookie}= 'set_value';
# Refer to set Cookie.
print $res->cookies->{new_cookie}->value;
# The cash control is setup.
$res->no_cache(1);
# Redirect it.
$res->redirect('/redirect_uri');
# ...etc.
DESCRIPTION
This module offers processing and the function that relates to the HTTP response.
CONFIGURATION
cookie
The default of cookie can be setup.
cookie => {
domain => 'mydomain',
path => '/',
expires => '+3M',
secure => 0,
},
domain
Domain that can be referred.
path
PATH that can be referred.
expires
Validity term.
secure
Secure flag.
Warning: Cookie cannot be referred to from the connection of usual http.
METHODS
new
Constructor. When the project is usually started, this is called.
* It is not necessary to call it specifying it.
BEGIN
request
Accessor to $e->request.
body ( [RESPONSE_CONTENT_BODY] )
The output contents are maintained by the SCALAR reference.
headers
HTTP::Headers object is returned.
header ( [CONTENT_BODY] )
The HTTP response header is assembled and it returns it by the SCALAR reference.
When CONTENT_BODY is given, 'Content-Length' header is added.
cookie ( [KEY], [VALUE] )
Set Cookie is set.
If VALUE is a usual character string, it is considered the value value. The following details can be set by giving the HASH reference.
value ... value of cookie.
path ... Reference PATH. - Default is '/'.
domain ... Reference domain.
expires ... Validity term.
secure ... Secure flag. - It starts making it to true at the SSL connection.
$response->cookie( 'cookie_name' => {
value => 'cookie_value',
path => '/active',
domain => 'mydomain.name',
expires => '+3H',
secure => 1,
});
cookies
The content of set Cookie is returned by the HASH reference.
no_cache ( [BOOL], [EXPIRES], [LAST_MODIFIED] )
The cash control is set.
When EXPIRES is given, $response->expires is set at the same time. If $response->expires is undefined, it defaults and '-1d' is set.
When LAST_MODIFIED is given, $response->last_modified is set at the same time. If $response->expires is undefined, it defaults and '-1d' is set.
0 Becomes invalid if it gives it. Moreover, please note that $response->last_modified and $response->is_expires also set 0 at the same time.
$response-E<gt>no_cache(1, '-3d', '-3d');
attachment ( [FILE_NAME] )
The download file name is set.
As 'Content-disposition: attachment; filename=[FILE_NAME]' result, a is added to the response header.
$response-E<gt>attachment('download.file');
window_target ( [TARGET_NAME] )
Window taget is specified.
content_encoding ( [ENCODING] )
content_encoding is specified.
status ( [STATUS_CODE] )
The status code is setup.
STATUS_CODE sets the figure of the treble that can surely be recognized with the HTTP response header.
When STATUS_STRING is omitted, acquisition is tried from %Egg::Response::Status.
$response-E<gt>status(400);
%Egg::Response::Status is as follows.
200 ... OK
301 ... Moved Permanently
302 ... Moved Temporarily
303 ... See Other
304 ... Not Modified
307 ... Temporarily Redirect
400 ... Bad Request
401 ... Unauthorized
403 ... Forbidden
404 ... Not Found
405 ... Method Not Allowed
500 ... Internal Server Error
The above-mentioned content is revokable from the controller etc.
%Egg::Response::Status= (
200 => 'OK',
302 => 'Found',
403 => 'Forbidden',
404 => 'Not Found',
500 => 'Internal Error',
);
status_string
STATUS_STRING set with $response->status is returned.
Half angle space is sure to be included in the head if it has defined it.
redirect ( [LOCATION_URI], [STATUS], [WINDOW_TARGET])
Redirecting is setup.
When STATUS is omitted, 302 is set.
When WINDOW_TARGET is specified, $response->window_target is set at the same time.
$response->redirect
( '/redirect', 307 => 'Temporarily Redirect', '_parent' );
if ($response->redirect) { true }
clear_body
The content of $response->body is deleted.
clear_cookies
The content of $response->cookies is initialized.
clear
The main variable of the response object is initialized.
result
The result code corresponding to $response->status is returned.
* Because this method is called from Egg by the automatic operation, it is not necessary to call it specifying it.
content_type ( [CONTENT_TYPE] )
The type of the output contents is setup.
As for default, 'content_type' of configuration or 'text/html' is used.
$response-E<gt>content_type('image/png');
* The character set is not set by the automatic operation for the text system. Please include it in a set value.
$response-E<gt>content_type('text/plain; charset=utf-8');
content_language ( [CONTENT_LANGUAGE] )
The language of contents is specified.
It defaults if 'content_language' of configuration is set and it is used.
$response-E<gt>content_language('ja');
nph ( [BOOL] )
The flag to assemble the response header of NPH scripting is hoisted.
* As for this method, debugging is not completed.
is_expires ( [EXPIRES_VER] )
The Expires header is set.
$response-E<gt>is_expires('+7d');
last_modified ( [LAST_MODIFIED_VAR] )
The last-Modified header is set.
$response-E<gt>last_modified('+1H');
SEE ALSO
HTTP::Headers, CGI::Cookie, Egg::Release,
AUTHOR
Masatoshi Mizuno <lushe@cpan.org>
COPYRIGHT
Copyright (C) 2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.