Hello Maxim, could you please respond to my previous message. Thanks. Dk.
On Tue, Jul 13, 2021 at 9:28 PM Dk Jack <dnj0...@gmail.com> wrote: > Hello Maxim, > Thanks for responding. Can I get some clarification on what you mean by > the statement below: > > "More flexibility can be achieved by reading the request body > earlier - for example, you can do this from your own module, or > with embedded scripting such as perl or njs." > > Are you suggesting that I use ngx_http_read_client_request_body api in my > module? > > http://nginx.org/en/docs/dev/development_guide.html#http_request_body > > I had similar trouble using that API with redirection. Are there some > tricks to getting > it to work when using that API? Are there any reference implementations > doing > redirection after inspecting the request body? > Thanks for your help! > > Dk. > > > Hello! > > It is generally too late to do any actions like "change the > > upstream/location etc" based on the body content, as the request > > body is usually read only when the location is already known and > > the upstream name is already obtained. Also consider > > "proxy_request_buffering off;" - reading the request body implies > > that nginx is sending the request body to the backend as well. > > That is, you can't really do more than modifying the request body > > or rejecting the request completely. > > > > You may, however, provide some variables from your body request > > body filter - and, if it's possible in your particular > > configuration, use these variables to do some conditional > > processing. > > > > Note thought that conditional processing needs to happen after the > > request body is read. As such, it is usually quite limited, > > especially when using standard modules, since the request body is > > usually read last. > > > > For example, with proxy the request body is read after the > > variables in the "proxy_pass" directive are evaluated, so even > > with "proxy_request_buffering on;" (the default) you cannot use > > the variables from your request body filter module to change the > > upstream. You can, however, use it to control headers in the > > upstream request by using "proxy_set_header" with appropriate > > variables (again, assuming buffered request body reading - for > > obvious reasons this won't work with "proxy_request_buffering > > off;"). > > > > More flexibility can be achieved by reading the request body > > earlier - for example, you can do this from your own module, or > > with embedded scripting such as perl or njs. > > > > -- > > Maxim Dounin > > http://mdounin.ru/ > > _______________________________________________ > > nginx-devel mailing list > > nginx-devel@nginx.org > > http://mailman.nginx.org/mailman/listinfo/nginx-devel > > > On Mon, Jul 12, 2021 at 12:47 PM Dk Jack <dnj0...@gmail.com> wrote: > >> Hi, >> In my module, I am trying to take actions based on the content of the >> body. To accomplish this, I am capturing the body using body file as shown >> in the example below: >> >> >> http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c >> >> This is working well. I can inspect the contents of the body and take >> different actions like rejecting requests etc. However, one of the actions >> I want to do is redirect the request based on the body content i.e if the >> content contains some string etc, then redirect the request i.e change the >> upstream/location etc. My question is, is it even possible to redirect a >> request in the body filter stage? Is there another way to do body >> capture/filter and still be able to redirect the request after inspecting >> the body? Any help, suggestions or sample code is appreciated. Thanks. >> >> Dk. >> >> >>
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel