Welcome! Log In Create A New Profile

Advanced

Re: $request_body bug?

agentzh
October 22, 2009 04:02AM
On Mon, Oct 5, 2009 at 7:08 PM, dennis cao <dennis__cao@hotmail.com> wrote:
> When I use this variable in log_format directive ,it can print the request_body in the log file
>
> but somewhere else it can't!
>

The $request_body variable only has values when the underlying content
handler or upstream handler or anything else has actually *read* the
request body from the tcp connection and stored it into
r->request_body slot.

The variable itself merely reads that buffered data and will never
read from socket itself. See the ngx_http_variable_request_body
function in src/http/ngx_http_variables.c in the Nginx source tree.

It can be easily demonstrated by means of my echo module [1]:

location /echo_body {
echo [$request_body];
}

Accessing /echo from the client side gives

$ echo "my body" | lwp-request -m POST 'http://localhost:8080/echo_body'
[]

As we can see, it's empty, because the "echo" module does NOT read the
client request body [2]. Now let's use something that actually reads
the body, like the standard proxy module:

location /echo_body2 {
proxy_pass $scheme://127.0.0.1:$server_port/dummy;
echo_after_body [$request_body];
}
location /dummy { echo_duplicate 0 ''; }

Accessing /echo_body2 gives the *desired* results:

$ echo "my body" | lwp-request -m POST 'http://localhost:8080/echo_body2'
[my body
]

Hope this helps :)

Cheers,
-agentzh

References
[1] echo-nginx-module wiki page: http://wiki.nginx.org/NginxHttpEchoModule
[2] On the C level, it's usually the ngx_http_read_client_request_body
function that does the body reading work, but can be also done by any
other code (as in the "upload" module).
Subject Author Posted

FCGI Perl

Gordon Pettey October 02, 2009 05:52PM

Re: FCGI Perl

Cliff Wells October 02, 2009 06:06PM

Re: FCGI Perl

Gordon Pettey October 02, 2009 07:58PM

Re: FCGI Perl

mike October 02, 2009 08:12PM

Re: FCGI Perl

Gordon Pettey October 03, 2009 12:42PM

Re: FCGI Perl

davidc October 05, 2009 05:25AM

$request_body bug?

dennisjanuary October 05, 2009 07:16AM

Re: FCGI Perl

Johnny fox Ucklenberg October 16, 2009 07:04PM

Re: FCGI Perl

Aleksandar Lazic October 16, 2009 07:14PM

Re: FCGI Perl

Kiswono Prayogo October 17, 2009 04:26AM

Re: FCGI Perl

Cliff Wells October 17, 2009 05:32AM

Re: FCGI Perl

Aleksandar Lazic October 17, 2009 06:50AM

Re: FCGI Perl

Johnny fox Ucklenberg October 17, 2009 11:54AM

Re: FCGI Perl

Aleksandar Lazic October 17, 2009 12:16PM

Re: FCGI Perl

Johnny Fox Ucklenberg October 17, 2009 02:20PM

Re: FCGI Perl

Aleksandar Lazic October 17, 2009 04:44PM

Re: FCGI Perl

Johnny Fox Ucklenberg October 17, 2009 06:22PM

Re: $request_body bug?

agentzh October 22, 2009 04:02AM

Re: $request_body bug?

agentzh October 22, 2009 09:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 215
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