Ticket #293: patch-nginx-limit-rate-after.txt

File patch-nginx-limit-rate-after.txt, 2.8 KB (added by Maxim Dounin, 13 years ago)

Just for history, correct patch to implement $limit_rate_after.

Line 
1# HG changeset patch
2# User Maxim Dounin <mdounin@mdounin.ru>
3# Date 1365008407 -14400
4# Node ID 7e39a357ddd2921381bed55c8758f643589fc115
5# Parent 4bcd35e7a0f0ab7e5e65bda9756cb28b61e252dd
6Added $limit_rate_after variable (ticket #293).
7
8The variable is fully identical to $limit_rate one, and allows to
9change a value set by limit_rate_after directive.
10
11diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
12--- a/src/http/ngx_http_core_module.c
13+++ b/src/http/ngx_http_core_module.c
14@@ -1524,6 +1524,10 @@ ngx_http_update_location_config(ngx_http
15 r->limit_rate = clcf->limit_rate;
16 }
17
18+ if (r->limit_rate_after == 0) {
19+ r->limit_rate_after = clcf->limit_rate_after;
20+ }
21+
22 if (clcf->handler) {
23 r->content_handler = clcf->handler;
24 }
25diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
26--- a/src/http/ngx_http_request.h
27+++ b/src/http/ngx_http_request.h
28@@ -420,6 +420,7 @@ struct ngx_http_request_s {
29 #endif
30
31 size_t limit_rate;
32+ size_t limit_rate_after;
33
34 /* used to learn the Apache compatible response length without a header */
35 size_t header_size;
36diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
37--- a/src/http/ngx_http_variables.c
38+++ b/src/http/ngx_http_variables.c
39@@ -298,6 +298,11 @@ static ngx_http_variable_t ngx_http_cor
40 offsetof(ngx_http_request_t, limit_rate),
41 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
42
43+ { ngx_string("limit_rate_after"), ngx_http_variable_request_set_size,
44+ ngx_http_variable_request_get_size,
45+ offsetof(ngx_http_request_t, limit_rate_after),
46+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
47+
48 { ngx_string("connection"), NULL,
49 ngx_http_variable_connection, 0, 0, 0 },
50
51diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
52--- a/src/http/ngx_http_write_filter_module.c
53+++ b/src/http/ngx_http_write_filter_module.c
54@@ -208,7 +208,7 @@ ngx_http_write_filter(ngx_http_request_t
55
56 if (r->limit_rate) {
57 limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1)
58- - (c->sent - clcf->limit_rate_after);
59+ - (c->sent - r->limit_rate_after);
60
61 if (limit <= 0) {
62 c->write->delayed = 1;
63@@ -249,14 +249,14 @@ ngx_http_write_filter(ngx_http_request_t
64
65 nsent = c->sent;
66
67- if (clcf->limit_rate_after) {
68+ if (r->limit_rate_after) {
69
70- sent -= clcf->limit_rate_after;
71+ sent -= r->limit_rate_after;
72 if (sent < 0) {
73 sent = 0;
74 }
75
76- nsent -= clcf->limit_rate_after;
77+ nsent -= r->limit_rate_after;
78 if (nsent < 0) {
79 nsent = 0;
80 }