[nginx] Upstream: variables support in proxy_limit_rate and friends.

Sergey Kandaurov pluknet at nginx.com
Mon May 27 15:19:01 UTC 2024


details:   https://hg.nginx.org/nginx/rev/2e9588d65dd9
branches:  
changeset: 9249:2e9588d65dd9
user:      J Carter <jordan.carter at outlook.com>
date:      Sat Nov 25 21:57:09 2023 +0000
description:
Upstream: variables support in proxy_limit_rate and friends.

diffstat:

 src/http/modules/ngx_http_fastcgi_module.c |  8 ++++----
 src/http/modules/ngx_http_proxy_module.c   |  8 ++++----
 src/http/modules/ngx_http_scgi_module.c    |  8 ++++----
 src/http/modules/ngx_http_uwsgi_module.c   |  8 ++++----
 src/http/ngx_http_upstream.c               |  2 +-
 src/http/ngx_http_upstream.h               |  2 +-
 6 files changed, 18 insertions(+), 18 deletions(-)

diffs (152 lines):

diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/modules/ngx_http_fastcgi_module.c	Sat Nov 25 21:57:09 2023 +0000
@@ -375,7 +375,7 @@ static ngx_command_t  ngx_http_fastcgi_c
 
     { ngx_string("fastcgi_limit_rate"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_size_slot,
+      ngx_http_set_complex_value_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_fastcgi_loc_conf_t, upstream.limit_rate),
       NULL },
@@ -2898,7 +2898,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_con
 
     conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
     conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
-    conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
+    conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
 
     conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
     conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
@@ -3015,8 +3015,8 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
                               prev->upstream.buffer_size,
                               (size_t) ngx_pagesize);
 
-    ngx_conf_merge_size_value(conf->upstream.limit_rate,
-                              prev->upstream.limit_rate, 0);
+    ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
+                              prev->upstream.limit_rate, NULL);
 
 
     ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/modules/ngx_http_proxy_module.c	Sat Nov 25 21:57:09 2023 +0000
@@ -494,7 +494,7 @@ static ngx_command_t  ngx_http_proxy_com
 
     { ngx_string("proxy_limit_rate"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_size_slot,
+      ngx_http_set_complex_value_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_proxy_loc_conf_t, upstream.limit_rate),
       NULL },
@@ -3371,7 +3371,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
 
     conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
     conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
-    conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
+    conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
 
     conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
     conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
@@ -3515,8 +3515,8 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
                               prev->upstream.buffer_size,
                               (size_t) ngx_pagesize);
 
-    ngx_conf_merge_size_value(conf->upstream.limit_rate,
-                              prev->upstream.limit_rate, 0);
+    ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
+                              prev->upstream.limit_rate, NULL);
 
     ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
                               8, ngx_pagesize);
diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/modules/ngx_http_scgi_module.c	Sat Nov 25 21:57:09 2023 +0000
@@ -223,7 +223,7 @@ static ngx_command_t ngx_http_scgi_comma
 
     { ngx_string("scgi_limit_rate"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_size_slot,
+      ngx_http_set_complex_value_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_scgi_loc_conf_t, upstream.limit_rate),
       NULL },
@@ -1301,7 +1301,7 @@ ngx_http_scgi_create_loc_conf(ngx_conf_t
 
     conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
     conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
-    conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
+    conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
 
     conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
     conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
@@ -1413,8 +1413,8 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t 
                               prev->upstream.buffer_size,
                               (size_t) ngx_pagesize);
 
-    ngx_conf_merge_size_value(conf->upstream.limit_rate,
-                              prev->upstream.limit_rate, 0);
+    ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
+                              prev->upstream.limit_rate, NULL);
 
 
     ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/modules/ngx_http_uwsgi_module.c	Sat Nov 25 21:57:09 2023 +0000
@@ -289,7 +289,7 @@ static ngx_command_t ngx_http_uwsgi_comm
 
     { ngx_string("uwsgi_limit_rate"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_size_slot,
+      ngx_http_set_complex_value_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_uwsgi_loc_conf_t, upstream.limit_rate),
       NULL },
@@ -1532,7 +1532,7 @@ ngx_http_uwsgi_create_loc_conf(ngx_conf_
 
     conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
     conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
-    conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
+    conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
 
     conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
     conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
@@ -1656,8 +1656,8 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
                               prev->upstream.buffer_size,
                               (size_t) ngx_pagesize);
 
-    ngx_conf_merge_size_value(conf->upstream.limit_rate,
-                              prev->upstream.limit_rate, 0);
+    ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
+                              prev->upstream.limit_rate, NULL);
 
 
     ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/ngx_http_upstream.c	Sat Nov 25 21:57:09 2023 +0000
@@ -3236,7 +3236,7 @@ ngx_http_upstream_send_response(ngx_http
     p->downstream = c;
     p->pool = r->pool;
     p->log = c->log;
-    p->limit_rate = u->conf->limit_rate;
+    p->limit_rate = ngx_http_complex_value_size(r, u->conf->limit_rate, 0);
     p->start_sec = ngx_time();
 
     p->cacheable = u->cacheable || u->store;
diff -r f7d53c7f7014 -r 2e9588d65dd9 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h	Thu May 23 19:15:38 2024 +0400
+++ b/src/http/ngx_http_upstream.h	Sat Nov 25 21:57:09 2023 +0000
@@ -156,7 +156,7 @@ typedef struct {
 
     size_t                           send_lowat;
     size_t                           buffer_size;
-    size_t                           limit_rate;
+    ngx_http_complex_value_t        *limit_rate;
 
     size_t                           busy_buffers_size;
     size_t                           max_temp_file_size;


More information about the nginx-devel mailing list