English: Nginx::ReadBody
Russian: Nginx::ReadBody::Russian
Nginx::ReadBody - nginx web server embeded perl module to read and evaluate a request body
Version 0.07
#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; }
nginx does not provide any methods to evaluate a request body. So this module does.
Nginx::ReadBody
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).
$variableName
$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).
Name of the nginx.conf variable contains a handler definition.
nginx.conf
Definition could be:
Evaluated to the reference to a subroutine just returning this code. Exactly like this:
$handler = eval "sub { return $variableValue; }";
Like My::Own::method.
My::Own::method
Evaluated to the reference to the named subroutine. Exactly like this:
$handler = eval "\\&$variableValue";
Like "sub {...}".
"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 case eval() failed reference to the subroutine always returning 500 is returned.
eval()
500
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.
Name of the variable to retrieve.
Value should be used in case a variable requested is not set or set to empty string. Could be undef.
undef
In case $defaultValue is not undef this variable will be set to this value for the rest of the whole request.
$read_body_debug
Controlls should debug messages be sent to error log or not.
0
''
Default. No debug messages.
1
'nonEmptyString'
Full debug info.
'0 but true'
Less verbose debug.
$read_body_nodata
Should contain a handler definition (see handler).
handler
Default is 400.
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
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.
$read_body_done
As soon as body is fully received this handler is called to check the content.
Should return TRUE or FALSE.
TRUE
FALSE
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 returns TRUE this handler is called.
$read_body_false
As soon as $read_body_check returns FALSE this handler is called.
None.
http://wiki.nginx.org/NginxEmbeddedPerlModule.
Daniel Podolsky, <tpaba@cpan.org>
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.
To install Nginx::ReadBody, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nginx::ReadBody
CPAN shell
perl -MCPAN -e shell install Nginx::ReadBody
For more information on module installation, please visit the detailed CPAN module installation guide.