Welcome! Log In Create A New Profile

Advanced

Re: [Nginx] perl module get an empty body

Maxim Dounin
August 10, 2012 09:56AM
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

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

[Nginx] perl module get an empty body

darkweaver871 August 10, 2012 06:03AM

Re: [Nginx] perl module get an empty body

darkweaver871 August 10, 2012 06:04AM

Re: [Nginx] perl module get an empty body

darkweaver871 August 10, 2012 07:03AM

Re: [Nginx] perl module get an empty body

darkweaver871 August 10, 2012 09:44AM

Re: [Nginx] perl module get an empty body

Maxim Dounin August 10, 2012 07:14AM

Re: [Nginx] perl module get an empty body

darkweaver871 August 10, 2012 09:46AM

Re: [Nginx] perl module get an empty body

darkweaver871 August 10, 2012 10:12AM

Re: [Nginx] perl module get an empty body

Maxim Dounin August 10, 2012 09:56AM

Re: [Nginx] perl module get an empty body

Maxim Dounin August 10, 2012 01:12PM

Re: [Nginx] perl module get an empty body

darkweaver871 August 12, 2012 06:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 275
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready