body capture and redirect

Dk Jack dnj0496 at gmail.com
Tue Sep 11 05:58:29 UTC 2018


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.

Regards,
Dk.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20180910/bb5ae173/attachment.html>


More information about the nginx-devel mailing list