Welcome! Log In Create A New Profile

Advanced

Re: [Nginx] perl module get an empty body

Maxim Dounin
August 10, 2012 01:12PM
Hello!

On Fri, Aug 10, 2012 at 10:12:56AM -0400, darkweaver871 wrote:

> OK, so is this better ?
>
> #!/usr/bin/perl
>
> package switcher_test;
> use nginx;
>
> use Sys::Syslog;
>
> my $facility = 'local2';
>
> sub handler {
> my $r = shift;
>
> return $r->has_request_body(\& test);
>
> }
>
> sub test {
> my $r = shift;
> if ($r->request_body =~ /.*test.*/) { return 3 };
> openlog('switcher', 'ndelay', $facility);
> syslog(LOG_DEBUG, 'request_body: '.$r->request_body);
> syslog(LOG_DEBUG, 'request_body_file: '.$r->request_body_file);
> return 4;
> }
>
> 1;
> __END__
>
>
> It still doesn't work this way.

Again: you can't use this code in perl_set directive. You have to
use perl directive:

perl switcher_test::handler;

And in perl package (mostly cut-n-paste from docs, with an
additional test for body):

package switcher_test;

use nginx;

sub handler {
my $r = shift;

if ($r->request_method ne "POST") {
return DECLINED;
}

if ($r->has_request_body(\&post)) {
return OK;
}

return HTTP_BAD_REQUEST;
}

sub post {
my $r = shift;

$r->send_http_header;

$r->print("request_body: \"", $r->request_body, "\"<br/>");
$r->print("request_body_file: \"", $r->request_body_file, "\"<br/>\n");

if ($r->request_body =~ /test/) {
return HTTP_BAD_REQUEST;
}

return OK;
}

1;

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: 111
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready