TRANSLATIONS
English: Nginx::ReadBody
Russian: Nginx::ReadBody::Russian
NAME
Nginx::ReadBody - nginx web server embeded perl module to read and evaluate a request body
Version 0.07
SYNOPSIS
#nginx.conf (part of)
location /post_here {
error_page 345 = @get_there;
error_page 346 = @good_post;
error_page 347 = @bad_post;
if ($request_method != POST)
{ return 345; }
set $read_body_debug 1;
set $read_body_check 'My::Own::check_userdata';
set $read_body_done 346;
set $read_body_nodata 347;
set $read_body_false 347;
perl Nginx::ReadBody::read;
}
DESCRIPTION
nginx does not provide any methods to evaluate a request body. So this module does.
The Nginx::ReadBody
methods
read($request);
-
Intended to be a location handler.
handler($request, $variableName, $defaultValue, $debug)
-
Handlers retriver and registrar. This method is intended to be used from other perl method acts as a location handler.
Method returns a reference to a subroutine defined by
$variableName
(or$defaultValue
).Value of
$variableName
is evaluated and the result is cached. See$variableName
for details.Parameters are:
$request
-
nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule).
$variableName
-
Name of the
nginx.conf
variable contains a handler definition.Definition could be:
- Digital code
-
Evaluated to the reference to a subroutine just returning this code. Exactly like this:
$handler = eval "sub { return $variableValue; }";
- Name of the perl subroutine
-
Like
My::Own::method
.Evaluated to the reference to the named subroutine. Exactly like this:
$handler = eval "\\&$variableValue";
- Definition of the perl subroutine
-
Like
"sub {...}"
.Evaluated to the reference to the defined subroutine. Exactly like this:
$handler = eval $variableValue;
I did not test this option at all! Could be dangerous with typos, etc.
In case
$variableName
value is not in any of these 3 forms or in caseeval()
failed reference to the subroutine always returning500
is returned. $defaultValue
-
Definition should be used in case a variable provided is not set or set to empty string.
$debug
-
Controlls a verbosity of the messages written to the error log. See $read_body_debug.
variable($request, $variableName, $defaultValue, $debug)
-
Smart - ok, not complitely stupid -
nginx.conf
variable retriever. This method is intended to be used from other perl method acts as a location handler.Parameters are:
$request
-
nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule).
$variableName
-
Name of the variable to retrieve.
$defaultValue
-
Value should be used in case a variable requested is not set or set to empty string. Could be
undef
.In case
$defaultValue
is notundef
this variable will be set to this value for the rest of the whole request. $debug
-
Controlls a verbosity of the messages written to the error log. See $read_body_debug.
nginx.conf
variables controlls the Nginx::ReadBody
behaviour
$read_body_debug
-
Controlls should debug messages be sent to error log or not.
$read_body_nodata
-
Should contain a
handler
definition (seehandler
).Default is
400
.In case a request does not have a body this
handler
is called.Handler is called with a nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule) as a single argument.
This handler should act as a location handler.
$read_body_check
-
Should contain a
handler
definition (seehandler
).Default is
'0 but true'
so in case you did not define your own$read_body_check
the request will be passed directly to$read_body_done
.As soon as body is fully received this
handler
is called to check the content.Handler is called with a nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule) as a single argument.
Should return
TRUE
orFALSE
. $read_body_done
-
Should contain a
handler
definition (seehandler
).Default is
500
that should be a clear indication you did not define an action should be performed with the request we just received a body for.As soon as
$read_body_check
returnsTRUE
thishandler
is called.Handler is called with a nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule) as a single argument.
This handler should act as a location handler.
$read_body_false
-
Should contain a
handler
definition (seehandler
).Default is
400
.As soon as
$read_body_check
returnsFALSE
thishandler
is called.Handler is called with a nginx request object (see http://wiki.nginx.org/NginxEmbeddedPerlModule) as a single argument.
This handler should act as a location handler.
EXPORT
None.
SEE ALSO
http://wiki.nginx.org/NginxEmbeddedPerlModule.
AUTHOR
Daniel Podolsky, <tpaba@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Daniel Podolsky
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.4 or, at your option, any later version of Perl 5 you may have available.