diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2013-05-11 18:49:42 +0400 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2013-05-11 18:49:42 +0400 |
commit | c3dea40b4596d480b8f4efa586ae052484509733 (patch) | |
tree | 142131edfe51688caa856bc12027c9964172bf16 /src | |
parent | 9cff79927a2c4a04df3d92681e4963cd1a4dee3f (diff) | |
download | nginx-c3dea40b4596d480b8f4efa586ae052484509733.tar.gz nginx-c3dea40b4596d480b8f4efa586ae052484509733.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/http/ngx_http_request.h | 1 | ||||
-rw-r--r-- | src/http/ngx_http_write_filter_module.c | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index bd842df7e..1babeb2b0 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -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; diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index 5594c7faa..f74dbc8ab 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c @@ -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; } |