mirror of
https://github.com/nginx/nginx.git
synced 2025-01-19 01:42:58 +08:00
Added r->limit_rate_after.
As of now, it allows to better control bandwidth limiting from additional modules. It is also expected to be used to add variables support to the limit_rate_after directive.
This commit is contained in:
parent
9cff79927a
commit
c3dea40b45
@ -420,6 +420,7 @@ struct ngx_http_request_s {
|
||||
#endif
|
||||
|
||||
size_t limit_rate;
|
||||
size_t limit_rate_after;
|
||||
|
||||
/* used to learn the Apache compatible response length without a header */
|
||||
size_t header_size;
|
||||
|
@ -207,8 +207,12 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
}
|
||||
|
||||
if (r->limit_rate) {
|
||||
if (r->limit_rate_after == 0) {
|
||||
r->limit_rate_after = clcf->limit_rate_after;
|
||||
}
|
||||
|
||||
limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1)
|
||||
- (c->sent - clcf->limit_rate_after);
|
||||
- (c->sent - r->limit_rate_after);
|
||||
|
||||
if (limit <= 0) {
|
||||
c->write->delayed = 1;
|
||||
@ -249,14 +253,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
|
||||
nsent = c->sent;
|
||||
|
||||
if (clcf->limit_rate_after) {
|
||||
if (r->limit_rate_after) {
|
||||
|
||||
sent -= clcf->limit_rate_after;
|
||||
sent -= r->limit_rate_after;
|
||||
if (sent < 0) {
|
||||
sent = 0;
|
||||
}
|
||||
|
||||
nsent -= clcf->limit_rate_after;
|
||||
nsent -= r->limit_rate_after;
|
||||
if (nsent < 0) {
|
||||
nsent = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user