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
content_type
Content_type is undefined contents type.
Deafult is 'text/html'.
* Please define it together if the setting of the character set is necessary.
content_type => 'text/html; charset=UTF-8',
no_content_length_regex
The pattern of Content-Type that doesn't send Conetnt-Length is set by the regular expression.
Deafult is '(?:^text/|/(?:rss\+)?xml)'.
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
Egg::Response::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], [REDIRECT_OPTION])
Redirecting is setup.
When STATUS is omitted, 302 is set.
The following options can be passed.
target => [TARGET_STRING]
template => [TEMPLATE_PATH]
When this option is given, $e->finished is not set.
And, it outputs it to the screen by processing the given template.
$response->redirect(
'/redirect', '307 Temporarily Redirect',
{ target=> '_parent', template=> 'redirect.tt' }
);
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');
no_content_length ( [BOOL] )
The content_length header is not temporarily sent.
Egg::Response::Headers METHODS
new ([ EGG::Response context ])
The object is returned.
* The object is HASH reference of the set header.
* The key is a name that lc is done for recognition.
* The content is ARRAY reference and [ "ORIGINAL NAME", "VALUE" ].
my $headers= $e->response->headers;
$headers->{X_AnyName}= 'any header.';
Reference to content.
$headers->{X_AnyName}[1];
Refer to all data.
for my $head (values %headers) {
print "$head->[0]: $head->[1]\r\n";
}
* The value is returned in order set by Tie::Hash::Indexed.
header ([HEAD_NAME], [VALUE])
The value set in [HEAD_NAME] is returned.
When [VALUE] is given, the value is set.
* If [VALUE] is undef, the data that relates to the key is deleted.
$header->header( X_AnyName => 'any_header' );
clear
ƒZƒbƒg�Ï‚Ý‚Ì’l‚ðƒf�[ƒ^‚ð�‰Šú‰»‚µ‚Ü‚·�B
$header->clear;
SEE ALSO
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 645:
Non-ASCII character seen before =encoding in 'ƒZƒbƒg�Ï‚Ý‚Ì’l‚ðƒf�[ƒ^‚ð�‰Šú‰»‚µ‚Ü‚·�B'. Assuming CP1252