ngx_http_read_client_request_body() and ACCESS_PHASE handler

Srebrenko Šehić ssehic at gmail.com
Fri Apr 23 15:21:00 MSD 2010


On Fri, Apr 23, 2010 at 10:54 AM, agentzh <agentzh at gmail.com> wrote:

Hi,

> When your rewrite/access handler returns NGX_AGAIN or NGX_DONE, your
> handler will get called again and again (mostly triggered by writable
> event and other hooks). (See ngx_http_core_module.c:1059.)
>
> When you handler returns NGX_OK, it means skipping all the handlers in
> the current rewrite/access phase, and giving the control to the first
> handler in the next phase. Normally we just return NGX_DONE here to
> let nginx's phase engine run the next handler in the current phase (if
> any).
>
> I think you should call ngx_http_read_client_request_body in your
> handler *only once*. If it gets called a second time, it will simply
> returns NGX_OK. (See ngx_http_request_body.c:43.)

Now, when a POST request (the one the fails) my access handler is only
called once. The access handler also only calls
ngx_http_read_client_request_body () once. What happens is that when
my callback handler (ngx_http_dummy_payload_handler) is called, the
request processing simply stops there. nginx error log shows this:

2010/04/23 13:14:04 [debug] 876#0: *3 access phase: 6
2010/04/23 13:14:04 [debug] 876#0: *3 access phase: 7
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_access_handler: enter
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body preread 436
2010/04/23 13:14:04 [debug] 876#0: *3 http read client request body
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body recv 1896
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body rest 10520
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_access_handler: rc=-2
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_access_handler:
rc=NGX_AGAIN, return
2010/04/23 13:14:04 [debug] 876#0: *3 http run request: "/test/upload.php?"
2010/04/23 13:14:04 [debug] 876#0: *3 http read client request body
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body recv 4380
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body rest 6140
2010/04/23 13:14:04 [debug] 876#0: *3 http run request: "/test/upload.php?"
2010/04/23 13:14:04 [debug] 876#0: *3 http read client request body
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body recv 1916
2010/04/23 13:14:04 [warn] 876#0: *3 a client request body is buffered
to a temporary file /var/nginx/tmp/client_body_temp/0000987649,
client: 192.168.0.85, server: 192.168.0.23, request: "POST
/test/upload.php HTTP/1.1", host: "192.168.0.23:8080", referrer:
"http://192.168.0.23:8080/test/upload.html"
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body recv 4224
2010/04/23 13:14:04 [debug] 876#0: *3 http client request body rest 0
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_payload_handler: enter
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_payload_handler: ctx->rc=-2
2010/04/23 13:14:04 [debug] 876#0: *3 ngx_http_dummy_payload_handler:
read->ready != 1

No more output after the above. read->ready != 1 shows the value of
r->connection->read->ready which is 0 when the return value of
ngx_http_read_client_request_body () is NGX_AGAIN.

[ ... snip ...]

> We're currently working on a module named ngx_form_input that calls
> ngx_http_read_client_request_body in a rewrite phase handler ;) We're
> passing all of our existing tests at the moment :)

Do you mind sharing this module (or relevant bits)? It might give me
some inspiration or guide me in the right direction.

Thanks for all your help.

Best regards,
Srebrenko



More information about the nginx-devel mailing list