[Nginx] perl module get an empty body
Maxim Dounin
mdounin at mdounin.ru
Fri Aug 10 13:54:11 UTC 2012
Hello!
On Fri, Aug 10, 2012 at 09:44:14AM -0400, darkweaver871 wrote:
> Hi Maxim,
>
> Thanks for your reply.
>
> I don't understand what you mean by "content handler" as I'm a noob in
> nginx perl usage (and I'm not sure it was clear enough for you). I
> tested http_content_length but it's empty also.
> I really need to have the calling request body (I deleted the major part
> of my code but I parse some stuff in).
>
> Let's say I want to return 3 to perl_set if the request body match
> "test" and 4 otherwise (and log it), I would do:
You have to use perl directive to handle request. Then you'll be
able to use $r->has_request_body(), see here:
http://nginx.org/en/docs/http/ngx_http_perl_module.html#methods
For conditional processing by other modules you may use
$r->internal_redirect() method.
> #!/usr/bin/perl
>
> package switcher_test;
> use nginx;
> use Sys::Syslog;
>
> my $facility = 'local2';
>
> sub handler {
> my $r = shift;
>
> openlog('tester', 'ndelay', $facility);
>
> $r->has_request_body(sub{});
> if ($r->request_body =~ /.*test.*/) { return 3 };
This is just wrong: $r->request_body will be only available when
body handler function is called ("sub{}" in the above code).
Using it here won't work.
[...]
Maxim Dounin
More information about the nginx
mailing list