Welcome! Log In Create A New Profile

Advanced

Re: Help! log phase is not executed due to r->count being non-zero

Maxim Dounin
October 13, 2014 01:08PM
Hello!

On Mon, Oct 13, 2014 at 12:41:04PM -0400, wangweixun wrote:

> Maxim,
>
> You are right. Since I need to make a hash of the original request's body, I
> do make call to ngx_http_read_client_request_body().
>
> What's the best way to decrement the count then? Simply "r->count--;" before
> returning from the module.

The ngx_http_read_client_request_body() increments r->count as it
expects that r->main->count will be decremented by twice:

- right after the ngx_http_read_client_request_body() call, by
ngx_http_finalize_request() as called automatically on you return
from content handlers;

- later in post_handler, by another ngx_http_finalize_request()
call.

If you do call ngx_http_read_client_request_body() from an access
handler, it should be fine to do "r->main->count--" in
post_handler directly.

(Note well that nginx generally doesn't assume that the request
body will be read before the content phase, and there may be
problems associated with this if you'll try reading request body
in an access handler.)

> By the way, in my access phase module, I need to send an subrequest and wait
> for its response asynchornously. ngx_http_read_client_request_body() also
> works asynchornously with a callback function, which apparently is not able
> to send a subrequest. What I did is registering two handlers in access
> phase. The first one does nothing but reading the request body only. The
> second one does the real work (subrequest, etc.). Does it sound right?

No, it doesn't. You should do the real work in post_handler.

--
Maxim Dounin
http://nginx.org/

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

Help! log phase is not executed due to r->count being non-zero

wangweixun October 11, 2014 12:28AM

Re: Help! log phase is not executed due to r->count being non-zero

wangweixun October 11, 2014 12:30AM

Re: Help! log phase is not executed due to r->count being non-zero

Maxim Dounin October 13, 2014 06:06AM

Re: Help! log phase is not executed due to r->count being non-zero

wangweixun October 13, 2014 12:41PM

Re: Help! log phase is not executed due to r->count being non-zero

Maxim Dounin October 13, 2014 01:08PM

Re: Help! log phase is not executed due to r->count being non-zero

wangweixun October 13, 2014 02:43PM

Re: Help! log phase is not executed due to r->count being non-zero

Maxim Dounin October 13, 2014 03:10PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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