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

Frankie Dintino fdintino at theatlantic.com
Thu Jan 3 05:21:15 UTC 2019


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20190103/5395b0ed/attachment.html>


More information about the nginx-devel mailing list