post body

Maxim Dounin mdounin at mdounin.ru
Wed Aug 8 18:34:05 UTC 2018


Hello!

On Tue, Aug 07, 2018 at 10:46:08PM -0700, Dk Jack wrote:

> Haven't received any response to inquiry. Would appreciate it if someone
> can comment.
> 
> > In my module, I'd like to look into the post body to decide if the request
> > should be allowed to proceed to origin server or not. Based on the examples
> > I could find I've coded this in my module. After some trial and error it
> > seems to be working. I am not sure if my implementation is 100% correct. I
> > would appreciate it if someone can go over my code below and let me know if
> > my implementation is correct. Especially, the body_complete_handler. Thanks.

You may want to read general request body reading guidelines here:

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

Your code suggests you've never seen these guidelines, so consider 
re-writing it after reading the above link.

Note that the above guidelines cover content phase handling.  In 
other request processing phases reqding the request body might be 
tricky and will require additional handling (if at all possible).  
In particular, you'll have to restore request phases processing 
after the call, and you might have to call 
ngx_http_finalize_request() yourself.  Consider looking into 
src/http/modules/ngx_http_mirror_module.c for an example.  Note 
well that required handling might depend on the exact request 
processing phase you are trying to use.

Note well that if you are trying to inspec the request body, 
writing a request body filter might be a better solution.  See 
here for a trivial example:

http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c

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


More information about the nginx-devel mailing list