Welcome! Log In Create A New Profile


How to use nginx to inspect body before sending response to client GET request

Posted by hkahlouche 
How to use nginx to inspect body before sending response to client GET request
January 24, 2019 09:33AM
I am looking for a way to use nginx in order to inspect a response body and then return the response to the client's GET request based on the result of inspection.
I have investigated the sub module filter http://nginx.org/en/docs/http/ngx_http_sub_module.html, but the pattern implemented cannot be reused for my purpose.
I also investigated the example module https://www.nginx.com/resources/wiki/extending/examples/body_filter/, but I was not able to get this module to work. Returning an error code from the body filter is too late and the request gets stuck after the 200 header was already sent.

What I want to achieve is the following:
- Block a client request and perform the following inspection handler (could be an asynch handler)
- Receive the response header (do not forward it yet)
- Receive and inspect/parse the response body
- Depending on the result of the inspection: pass/fail
+ pass:
* send the response header to the client,
* send the response body buffers to the client
+ fail:
* send an error code response header to the client,
* discard the response body buffers

Thanks in advance

Edited 1 time(s). Last edit at 01/24/2019 09:40AM by hkahlouche.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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