Welcome! Log In Create A New Profile

Advanced

Trying to understand request body handling.

July 25, 2019 02:08AM
Hi,
In my module I have the following requirements:

- Inspect the contents of the POST body in the request
- If the body content matches the configured regex, then take one of the
following actions:
- Return forbidden
- Redirect to another location without using 302
- If the content doesn't match the configured regex, then simply forward
the request to proxy_pass destination.

I used 'ngx_http_read_client_request_body'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.

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?

I also modified my module to use body filters as described in
https://nginx.org/en/docs/dev/development_guide.html#http_body_filters 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.

regards,
Dk.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Trying to understand request body handling.

dnj0496 599 July 25, 2019 02:08AM

Re: Trying to understand request body handling.

dnj0496 441 July 26, 2019 05:12PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 288
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready