processing a request without body

Maxim Dounin mdounin at mdounin.ru
Thu Jan 11 21:59:36 UTC 2024


Hello!

On Fri, Jan 12, 2024 at 03:26:39AM +0800, Muhammad Nuzaihan wrote:

> Hi Maxim,
> 
> After searching the archives, I found the solution which you had
> answered before:
> https://www.ruby-forum.com/t/trouble-getting-the-request-body-of-a-http-post/180463/4
> 
> The code that reads the body is:
>     rc = ngx_http_read_client_request_body(r,
>                               ngx_http_foo_body_handler);
> 
>     if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
>       return rc;
>     }
> 
> Can i buy you coffee?

You may want to start with basic examples and the dev guide, 
specifically:

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

Note though that reading the request body during phase processing, 
in contrast to doing so in a content handler, requires special 
precautions.  In particular, you'll have to call 
ngx_http_finalize_request(NGX_DONE) to ensure correct request 
reference counting:

https://hg.nginx.org/nginx/file/tip/src/http/modules/ngx_http_mirror_module.c#l120

Further, to resuming phase processing after reading the request 
body you'll have to restore r->write_event_handler and call 
ngx_http_core_run_phases().  See here in the mirror module for an 
example:

https://hg.nginx.org/nginx/file/tip/src/http/modules/ngx_http_mirror_module.c#l144

Hope this helps.

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


More information about the nginx-devel mailing list