]> git.kaiwu.me - njs.git/commitdiff
Fetch: disable keepalive for dynamic proxy
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 May 2026 05:19:46 +0000 (22:19 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 1 Jun 2026 15:44:59 +0000 (08:44 -0700)
nginx/ngx_js_fetch.c
nginx/ngx_qjs_fetch.c
nginx/t/js_fetch_proxy_keepalive.t

index ac19d704e7a3089f58170cc86efec0e6544e795f..3b6db4a278f9e632aa403b3476a6060d273cf894 100644 (file)
@@ -1087,7 +1087,8 @@ ngx_js_fetch_alloc(njs_vm_t *vm, ngx_pool_t *pool, ngx_log_t *log,
     http->conf = conf;
 
     http->content_length_n = -1;
-    http->keepalive = (conf->fetch_keepalive > 0);
+    http->keepalive = (conf->fetch_keepalive > 0
+                       && !ngx_js_conf_dynamic_proxy(conf));
 
     http->append_headers = ngx_js_fetch_append_headers;
     http->ready_handler = ngx_js_fetch_process_done;
index 6f97e7f3faa7fcd569fa1626b602ba7a5554651b..0d510adb1c3ab130c40c48e089007e0b915a762c 100644 (file)
@@ -1149,7 +1149,8 @@ ngx_qjs_fetch_alloc(JSContext *cx, ngx_pool_t *pool, ngx_log_t *log,
     http->conf = conf;
 
     http->content_length_n = -1;
-    http->keepalive = (conf->fetch_keepalive > 0);
+    http->keepalive = (conf->fetch_keepalive > 0
+                       && !ngx_js_conf_dynamic_proxy(conf));
 
     ngx_qjs_arg(http->response.header_value) = JS_UNDEFINED;
 
index 422cf1b7154f0c8c0f3dcc09eaa67eb051776b76..7f119989773f074b757c86d4439ec12a4b0015e0 100644 (file)
@@ -58,6 +58,13 @@ http {
             js_fetch_proxy http://user:pass@127.0.0.1:%%PORT_8082%%;
             js_content test.https_fetch;
         }
+
+        location /https_via_dynamic_proxy_keepalive {
+            set $proxy_url http://user:pass@127.0.0.1:%%PORT_8082%%;
+            js_fetch_keepalive 4;
+            js_fetch_proxy $proxy_url;
+            js_content test.https_fetch;
+        }
     }
 
     server {
@@ -185,7 +192,7 @@ foreach my $name ('example.com', 'example.org') {
                . $t->read_file('intermediate.crt'));
 }
 
-$t->try_run('no js_fetch_proxy')->plan(4);
+$t->try_run('no js_fetch_proxy')->plan(6);
 
 $t->run_daemon(\&https_proxy_daemon, $p2);
 $t->run_daemon(\&dns_daemon, port(8981), $t);
@@ -202,6 +209,10 @@ like(http_get('/https_via_proxy_keepalive?domain=example.com'),
        qr/COM:2$/, 'https keepalive through proxy 2');
 like(http_get("/https_via_proxy_keepalive?domain=example.org&port=$p4"),
        qr/ORG:2$/, 'https keepalive through proxy different hostnames 2');
+like(http_get('/https_via_dynamic_proxy_keepalive?domain=example.com'),
+       qr/COM:1$/, 'https dynamic proxy keepalive disabled 1');
+like(http_get('/https_via_dynamic_proxy_keepalive?domain=example.com'),
+       qr/COM:1$/, 'https dynamic proxy keepalive disabled 2');
 
 ###############################################################################