request body filter

Dk Jack dnj0496 at gmail.com
Tue Aug 10 17:04:20 UTC 2021


Hello Maxim,
Thanks for responding. My configuration to determine if I should inspect
the body or not is not part of the location config since it's dynamic and I
am receiving this config from an external app. The configuration is updated
asynchronously. My module matches the requests against this external
information and then enables the body filter. Not sure if I can use the
location configuration as you suggested. Please suggest any modules using
location config and doing something similar to my module. Thanks.

Regards,
Dk.

On Tue, Aug 10, 2021 at 6:19 AM Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Mon, Aug 09, 2021 at 11:48:35AM -0700, Dk Jack wrote:
>
> > Hi,
> > In my module, I am inspecting the request body. My body filter init code
> is
> > shown below:
> >
> > int
> > module_body_filter_init(ngx_conf_t *cf)
> > {
> >   ngx_http_next_body_filter = ngx_http_top_request_body_filter;
> >   ngx_http_top_request_body_filter = nginx_module_inspect_body_filter;
> >
> >   return NGX_OK;
> > }
> >
> > Even though I have the above initialization, I do not want to inspect the
> > body for all requests. I figured the body filter would be invoked in the
> > content phase. Hence, I registered a handler in the NGX_HTTP_ACCESS_PHASE
> > to create my module context and set the flag to inspect the request body.
> > This works in some cases but is inconsistent. It looks like my
> > inspect_body_filter function is getting called before my access handler
> > function in some cases. I've now moved my handler to POST_READ_PHASE to
> get
> > consistent results. Is this the correct way to solve this problem? Are
> > there any other ways to accomplish this or are there any pitfalls to this
> > approach. Any help is appreciated. Thanks.
>
> Request body filters are called when the request body reading
> happens.  This can happen at any phase, especially when using
> other 3rd party modules, and it is generally incorrect to assume
> that some phase handler is called before reading the request body.
>
> Note well that module contexts are cleared on internal
> redirections, and this might also be a problem for your approach.
>
> A better approach would be to depend on the location configuration
> instead.  And do appropriate checks in the request body filter
> itself if some run-time logic is needed.
>
> --
> 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/20210810/2fc9765d/attachment.htm>


More information about the nginx-devel mailing list