caddy
caddy copied to clipboard
Feature Request: Bandwidth Limiting
Is it possible to allow bandwidth limiting.
It would allow you to set the download speed for certain users to say 50k.
It would be good to also allow rate limiting only after an initial limit has been set.
It would be good to allow rate limiting of only certain resources by path.
In NGINX it's called rate limit: http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate
An example NGINX config looks like this:
location /flv/ {
flv;
limit_rate_after 500k;
limit_rate 50k;
}
This would limit anything in the flv directory to 50k after 500k of data has been downloaded.
This should definitely be possible. It's probably quite simple.
A quick Google shows some simple projects that do this by wrapping the connection and doing the throttling in the Read and Write methods. https://github.com/jamesmoriarty/goforward/blob/master/goforward.go
This might be better as a plugin though. So if anyone wants to take a crack at porting this to Caddy, go for it!
Yeah, this can easily be done with a listener wrapper plugin (if you want to throttle ALL reads/writes on the TCP connection) or an HTTP handler plugin (if you only want to throttle reading/writing the response body).
Caddy's layer4 module has a feature kind of like this: https://github.com/mholt/caddy-l4/blob/master/modules/l4throttle/throttle.go (we call it a "throttle")
Something very similar could be done by a listener wrapper plugin for Caddy's http app.
I think unless there is a lot of demand for this feature, and unless it is generally useful, I will probably defer to the community to implement this plugin. It should be pretty straightforward.
As this issue is no longer actionable for our project, I'll close this, but feel free to continue discussion, and hopefully someone will take a few minutes to implement this module!
any update on this?
You could try our Caddy Bandwidth plugin: https://github.com/mediafoundation/caddy-bandwidth