Add patch in ngx_http_request_body.c which enhances the request body filter module

Maxim Dounin mdounin at mdounin.ru
Wed Aug 14 13:09:57 UTC 2019


Hello!

On Tue, Aug 13, 2019 at 03:31:19AM +0000, 黎 红波 wrote:

> Hello, I found the Nginx is not considered completely for request body filter. So I submit my patch. I hope my patch could be accepted and merged under your careful consideration.
> 
> Thank you!

> # HG changeset patch
> # User Hongbo Li <lihb2113 at outlook.com>
> # Date 1565599828 -28800
> #      Mon Aug 12 16:50:28 2019 +0800
> # Node ID 21e669b708e8e35a1f2d3d3cf72eb62cada0a347
> # Parent  fcd92ad76b7bb04b46c4b8fdfe14b6065acadf7d
> Allowed self-defined request body filter module return AGAIN.
> 
> When adding self-defined request body filter module, such as upload limit module, Nginx will return NGX_HTTP_INTERNAL_SERVER_ERROR if the added request body filter module return AGAIN at the same time all request body only in buffer (with request_body_no_buffering is 0). This will cause reading request body repeatedly until timeout. We should judge whether it is the last part of request body.
> 
> diff -r fcd92ad76b7b -r 21e669b708e8 src/http/ngx_http_request_body.c
> --- a/src/http/ngx_http_request_body.c	Thu Aug 01 13:50:07 2019 +0300
> +++ b/src/http/ngx_http_request_body.c	Mon Aug 12 16:50:28 2019 +0800
> @@ -306,6 +306,10 @@
>                      }
>                  }
>  
> +                if (rb->rest == 0) {
> +                    break;
> +                }
> +
>                  if (rb->busy != NULL) {
>                      if (r->request_body_no_buffering) {
>                          if (c->read->timer_set) {

Request body filters are not allowed to return NGX_AGAIN, and 
doing so will break things.  While your patch might somewhat 
improve things, it certainly doesn't make it possible for request 
body filters to return NGX_AGAIN: for example, HTTP/2 code simply 
doesn't tolerate anything but NGX_OK.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list