<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div>In my module I have the following requirements:</div><div><br></div><div>- Inspect the contents of the POST body in the request</div><div>- If the body content matches the configured regex, then take one of the following actions:</div><div>  - Return forbidden</div><div>  - Redirect to another location without using 302</div><div>- If the content doesn't match the configured regex, then simply forward the request to proxy_pass destination.</div><div><br></div><div>I used '<span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;text-align:justify">ngx_http_read_client_request_body'</span>function accumulate the body contents inspect it. I invoked this function from a pre-access handler. My request body handler callback gets called and I am able to inspect the body and I am able to take the actions I have mentioned above.</div><div><br></div><div>However, it is not working completely as I expected. For example, when I return forbidden after body inspection, my client is receiving the forbidden message and the status code I've setup. However, the request seems to also get forwarded to the origin. In the error.log, I see 'header already sent while reading response from upstream' message. I see a similar issue when redirecting. The request is getting sent to origin server as well as the server I redirected to after inspection. Which leads me to believe that the request is being forwarded based on the proxy_pass rule while my module is still accumulating the body i.e before my body_complete handler is called. Is my understanding correct? If so, is there a way to stall the forwarding of the request till my module has completed the inspection? Is there something in the request I need to set in the earlier phases when I doing this sort of thing?</div><div><br></div><div>I also modified my module to use body filters as described in <a href="https://nginx.org/en/docs/dev/development_guide.html#http_body_filters" style="font-family:-webkit-standard">https://nginx.org/en/docs/dev/development_guide.html#http_body_filters</a> to see if it'd help my cause. However, I can't seem to get redirect working after inspecting the body. Any suggestions on the correct approach to solving my issues while adhering to requirements. Any help is greatly appreciated. Thanks.</div><div><br></div><div>regards,</div><div>Dk.</div><div><br></div></div></div></div></div></div>