body capture and redirect

Dk Jack dnj0496 at gmail.com
Tue Sep 11 19:28:52 UTC 2018


Hello Maxim,

On your last suggestion...

"In the request body filter you have to either return a fatal  error, or
raise some internal flag for your processing, and then
act on this flag after the body is fully read."

How can I be certain when my body is fully read? Currently, when my body
filter is invoked,
I am walking the chain of buffers and saving it to a temporary buffer to
perform my lookup.
That is why I am little confused by your statement.Thanks for all your help.

regards,
dk

On Tue, Sep 11, 2018 at 5:55 AM Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Mon, Sep 10, 2018 at 10:58:29PM -0700, Dk Jack wrote:
>
> > Hi,
> > In my module, I am trying to forward the request to my server based on
> the
> > content of the request body. To acheive this, I've added a body capture
> > filter to capture the body. My code is something like this...
> >
> > static ngx_int_t
> > nginx_inspect_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
> > {
> >
> >     ... // extract body
> >     if (if_content_of_interest_in_body(body, body_length)) {
> >         ngx_str_t uri = ngx_string("/my_location");
> >         ngx_http_internal_redirect(r, &url, NULL);
> >         ngx_http_finalize_request(r, NGX_DONE);
> >         return NGX_DONE;
> >     }
> >     ...
> > }
> >
> > I have the following conf for '/my_location':
> >
> >   server {
> >      ...
> >      location / {
> >          ...
> >      }
> >      location /my_location {
> >          proxy_pass http://myserver;
> >      }
> >    }
> >
> > However, I am running into an issue with my code. The request seems to
> get
> > forwarded to my server like I expected. However, my connection seems to
> > hang. Looks like the server seems to be waiting to read more data from
> > nginx. When I interrupt my server (ctrl-c; its a simple python server),
> it
> > sort breaks out of the read loop and a response is returned. Sending the
> > same request to my server without sending it through my module in nginx,
> > behaves correctly.
> >
> > Could someone more experienced in nginx, point out what I am doing wrong?
> > Is redirect allowed from a body filter handler? Thanks for your help in
> > advance.
>
> Assuming the "nginx_inspect_body_filter" function is installed
> into the request body filter chain via the
> ngx_http_top_request_body_filter, what you are trying to do is
> wrong.
>
> You cannot stop reading the request body at arbitrary time and
> switch to different processing.  This will leave the body
> half-read, in an inconsistent state, and this in turn will cause
> various problem during further processing.  That is, connection
> hang you see is an expected result.
>
> In the request body filter you have to either return a fatal
> error, or raise some internal flag for your processing, and then
> act on this flag after the body is fully read.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20180911/248cc33e/attachment.html>


More information about the nginx-devel mailing list