[Nginx] perl module get an empty body

darkweaver871 nginx-forum at nginx.us
Fri Aug 10 13:44:14 UTC 2012


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:

#!/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 };

        syslog(LOG_DEBUG, 'request_body: '.$r->request_body);

        return 4;
}

1;
__END__

It works but when another program (developed by another company who
don't want to change the code) POST to my Nginx using:
 
pList.append('%s=%s' % (paramKey,
urllib.quote_plus(unicode(paramValue))))

(cf. my test program above)

it doesn't works and Nginx timeouts.

According to your previous answer how would you do it ?

Thanks.

Rémi

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,229560,229570#msg-229570



More information about the nginx mailing list