read request body with http2

Maxim Dounin mdounin at mdounin.ru
Mon Oct 14 14:25:58 UTC 2019


Hello!

On Sun, Oct 13, 2019 at 08:47:16PM -0400, Ansuel wrote:

> Hello, i'm developing a custom module that needs to read the request body to
> get some data from it. 
> To read the request body i'm using 
> 
> ngx_http_read_client_request_body 
> 
> and in the callback i use 
> 
> for (in = r->request_body->bufs; in; in = in->next) {
> 			len = ngx_buf_size(in->buf);
> 			ngx_memcpy(buffer + pos,in->buf->pos,len);
> 			pos += len;
> 	}
> 
> To put the data in a char buffer

Note that unless you've specifically tuned client_body_buffer_size 
and client_max_body_size, there can be in-file buffers in 
r->request_body->bufs.

> Aside from the fact that put request body in a buffer is wrong because it
> can became very big...
> 
> I notice that if i enable http2 connection, the request body doesn't get
> read at all.... I notice the function read_client_request_body is never
> called... 
> Am i missing something or there are some specail way to wait/read the
> request body with http2? By disabling it (remove support from nginx.conf)
> the module works as it should and i can correctly read the request body.

There is no "read_client_request_body" function in nginx.  If 
that's how you've called your handler function you pass into 
ngx_http_read_client_request_body(), and it's never called - 
probably there is something wrong with how you handle things.

Consider looking at the examples at the examples at the 
Developer's Guide, probably you'll be able to find out what you've 
did wrong, and/or will be able to reimplement it correctly from 
scratch:

http://nginx.org/en/docs/dev/development_guide.html#http_request_body

> I really hope this can be solved as i don't want to remove http2 support for
> this...

Certainly reading request body works fine with HTTP/2, and it is 
used in many standard modules, including proxy.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list