Welcome! Log In Create A New Profile

Advanced

rate limit request body read from a body filter? (nginx-upload-module)

Frankie Dintino
January 03, 2019 12:22AM
Hi,

I'm currently trying to rewrite https://github.com/fdintino/nginx-upload-module/ https://github.com/fdintino/nginx-upload-module/ as a request body filter, in order to simplify the code and future-proof it (as it's currently written, there's a lot of copypasta from ngx_http_request_body.c that is very fragile and probably already incompatible with new features and third party modules).

I'm nearly done this work, but I've hit a stumbling block trying to port the upload rate limiting feature. The current implementation completely overrides the request handler, so rate-limiting the request body is pretty trivial: if you need to delay the next buffer read, to stay within the rate limit, you can set c->read->delayed = 1, call ngx_add_timer(c->read, delay), and return NGX_AGAIN.

When I try this from the request body filter, I'm able to delay the very next read event, but afterwards when control is returned to the outer request handler, the rate that read buffers get consumed is no longer within my control (also, returning NGX_AGAIN from the body handler to the http2 request handler doesn't work at all—it raises a 500—but that's another issue).

So it seems to me that—if I want to keep the upload rate limiting feature—I'm going to have to do it somewhere else, maybe in a custom read event handler. Is there another option I'm not thinking of? And if I have to do it in a custom read_event_handler, does anyone have pointers for how I can do this in the least obtrusive way?

Thanks!

Frankie Dintino
The Atlantic

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

rate limit request body read from a body filter? (nginx-upload-module)

Frankie Dintino 429 January 03, 2019 12:22AM

Re: rate limit request body read from a body filter? (nginx-upload-module)

Maxim Dounin 178 January 09, 2019 02:04PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready