<div dir="ltr"><div># HG changeset patch</div><div># User Miroslav Nový <<a href="mailto:miranovy@gmail.com" target="_blank">miranovy@gmail.com</a>></div><div># Date 1534234559 0</div><div>#      Tue Aug 14 08:15:59 2018 +0000</div><div># Node ID 1a8327b50f7844cbe68226f54de60632189327f4</div><div># Parent  70c6b08973a02551612da4a4273757dc77c70ae2</div><div>limit_rate_after support variables</div><div><br></div><div>Example of use:</div><div><div>location / {</div><div><span style="white-space:pre">    </span>    root /var/www/default/;</div><div>            index  index.html index.htm;</div><div><br></div><div><span style="white-space:pre">  </span>    set $my_limit_rate_after 2m;</div><div><br></div><div><span style="white-space:pre">   </span>    limit_rate_after $my_limit_rate_after;</div><div><span style="white-space:pre">  </span>    limit_rate 2k;</div><div><br></div><div><span style="white-space:pre"> </span>    access_by_lua_block {</div><div><span style="white-space:pre">           </span>ngx.var.my_limit_rate_after = '10m'</div><div><span style="white-space:pre">   </span>    }</div><div><br></div><div>        }</div></div><div><br></div><div>diff -r 70c6b08973a0 -r 1a8327b50f78 src/http/ngx_http_core_module.c</div><div>--- a/src/http/ngx_http_core_module.c<span style="white-space:pre-wrap">        </span>Fri Aug 10 21:54:46 2018 +0300</div><div>+++ b/src/http/ngx_http_core_module.c<span style="white-space:pre-wrap">      </span>Tue Aug 14 08:15:59 2018 +0000</div><div>@@ -487,7 +487,7 @@</div><div>     { ngx_string("limit_rate_after"),</div><div>       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF</div><div>                         |NGX_CONF_TAKE1,</div><div>-      ngx_conf_set_size_slot,</div><div>+      ngx_http_set_complex_value_slot,</div><div>       NGX_HTTP_LOC_CONF_OFFSET,</div><div>       offsetof(ngx_http_core_loc_conf_t, limit_rate_after),</div><div>       NULL },</div><div>@@ -3364,6 +3364,7 @@</div><div>      *     clcf->alias = 0;</div><div>      *     clcf->gzip_proxied = 0;</div><div>      *     clcf->keepalive_disable = 0;</div><div>+     *     clcf->limit_rate_after = NULL;</div><div>      */</div><div> </div><div>     clcf->client_max_body_size = NGX_CONF_UNSET;</div><div>@@ -3393,7 +3394,6 @@</div><div>     clcf->send_lowat = NGX_CONF_UNSET_SIZE;</div><div>     clcf->postpone_output = NGX_CONF_UNSET_SIZE;</div><div>     clcf->limit_rate = NGX_CONF_UNSET_SIZE;</div><div>-    clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;</div><div>     clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;</div><div>     clcf->keepalive_header = NGX_CONF_UNSET;</div><div>     clcf->keepalive_requests = NGX_CONF_UNSET_UINT;</div><div>@@ -3623,8 +3623,8 @@</div><div>     ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,</div><div>                               1460);</div><div>     ngx_conf_merge_size_value(conf->limit_rate, prev->limit_rate, 0);</div><div>-    ngx_conf_merge_size_value(conf->limit_rate_after, prev->limit_rate_after,</div><div>-                              0);</div><div>+    ngx_conf_merge_ptr_value(conf->limit_rate_after, prev->limit_rate_after,</div><div>+                              NULL);</div><div>     ngx_conf_merge_msec_value(conf->keepalive_timeout,</div><div>                               prev->keepalive_timeout, 75000);</div><div>     ngx_conf_merge_sec_value(conf->keepalive_header,</div><div>diff -r 70c6b08973a0 -r 1a8327b50f78 src/http/ngx_http_core_module.h</div><div>--- a/src/http/ngx_http_core_module.h<span style="white-space:pre-wrap">    </span>Fri Aug 10 21:54:46 2018 +0300</div><div>+++ b/src/http/ngx_http_core_module.h<span style="white-space:pre-wrap">      </span>Tue Aug 14 08:15:59 2018 +0000</div><div>@@ -351,7 +351,7 @@</div><div>     size_t        send_lowat;              /* send_lowat */</div><div>     size_t        postpone_output;         /* postpone_output */</div><div>     size_t        limit_rate;              /* limit_rate */</div><div>-    size_t        limit_rate_after;        /* limit_rate_after */</div><div>+    ngx_http_complex_value_t        *limit_rate_after;        /* limit_rate_after */</div><div>     size_t        sendfile_max_chunk;      /* sendfile_max_chunk */</div><div>     size_t        read_ahead;              /* read_ahead */</div><div>     size_t        subrequest_output_buffer_size;</div><div>diff -r 70c6b08973a0 -r 1a8327b50f78 src/http/ngx_http_write_filter_module.c</div><div>--- a/src/http/ngx_http_write_filter_module.c<span style="white-space:pre-wrap">     </span>Fri Aug 10 21:54:46 2018 +0300</div><div>+++ b/src/http/ngx_http_write_filter_module.c<span style="white-space:pre-wrap">      </span>Tue Aug 14 08:15:59 2018 +0000</div><div>@@ -220,7 +220,26 @@</div><div> </div><div>     if (r->limit_rate) {</div><div>         if (r->limit_rate_after == 0) {</div><div>-            r->limit_rate_after = clcf->limit_rate_after;</div><div>+            r->limit_rate_after = 0;</div><div>+</div><div>+            if (clcf->limit_rate_after != NULL) {</div><div>+                ngx_str_t res;</div><div>+                size_t    st;</div><div>+</div><div>+                if (ngx_http_complex_value(r, clcf->limit_rate_after, &res)</div><div>+                    != NGX_OK)</div><div>+                {</div><div>+                    return NGX_ERROR;</div><div>+                }</div><div>+</div><div>+                st = ngx_parse_size(&res);</div><div>+                if (st != (size_t) NGX_ERROR) {</div><div>+                    r->limit_rate_after = st;</div><div>+                } else {</div><div>+                    ngx_log_error(NGX_LOG_ALERT, c->log, 0, </div><div>+                                  "limit_rate_after has bad value");</div><div>+                }</div><div>+            }</div><div>         }</div><div> </div><div>         limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1)</div><div><br></div></div>