Welcome! Log In Create A New Profile


Re: Got "http reading blocked" on second request with same connection

Maxim Dounin
November 10, 2021 02:28PM

On Tue, Nov 09, 2021 at 06:40:01PM -0500, frdcybermatrix wrote:

> Hi I'm having problem with my custom nginx module.
> I created nginx module to detect wether the request is authorized or not,
> and I need to check request body. So I use ngx_http_read_client_request_body
> Modules work perfectly on one request at a time. For example: 'curl -v
> localhost'
> But the problem happen when second request happen using same connection. For
> example: 'curl -v localhost localhost'.
> When I try to debug I got "http reading blocked". But when I remove
> ngx_http_read_client_request_body, and leave body empty, it's work
> static ngx_int_t
> ngx_http_ai_inspect_handler(ngx_http_request_t *r)
> {
> ngx_chain_t *in;
> ngx_http_read_client_request_body(r, ngx_http_ai_inspect_post_handler);
> off_t len = 0;
> if (r->request_body != NULL) {
> for (in = r->request_body->bufs; in; in = in->next) {
> len += ngx_buf_size(in->buf);
> }
> }
> }

First of all, it is not correct to use the request body after the
ngx_http_read_client_request_body() call: the request body might
not be available yet at this point. Instead, you should wait till
the post handler is called, and only use the body after it's
called. See the development guide for details:


Second, when you are reading the request body from phase handlers,
there are additional things to consider. In particular:

- Things to do after the ngx_http_read_client_request_body() might
differ from what one normally does in content handler, notably
you'll have to call ngx_http_finalize_request(NGX_DONE) yourself;

- It is important to restore phase processing after the request
body is read and you've done with it, so you'll have to
set r->write_event_handler back to ngx_http_core_run_phases in
the post handler and run ngx_http_core_run_phases() when you're

Refer to the src/http/modules/ngx_http_mirror_module.c for an

Maxim Dounin
nginx mailing list
Subject Author Posted

Got "http reading blocked" on second request with same connection

frdcybermatrix November 09, 2021 06:40PM

Re: Got "http reading blocked" on second request with same connection

Maxim Dounin November 10, 2021 02:28PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

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