[PATCH] Proxy: support variables for proxy_method directive

Dmitry Lazurkin dilaz03 at gmail.com
Mon Oct 17 16:56:56 UTC 2016


# HG changeset patch
# User Dmitry Lazurkin <dilaz03 at gmail.com>
# Date 1476631441 -10800
#      Sun Oct 16 18:24:01 2016 +0300
# Node ID b8d4a355e3ce2e47eff9424b432a22a4c86d9f08
# Parent  20eb4587225b3d7849ec5ece5732ed261226d365
Proxy: support variables for proxy_method directive.

diff -r 20eb4587225b -r b8d4a355e3ce src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Fri Oct 14 19:48:26 2016 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c	Sun Oct 16 18:24:01 2016 +0300
@@ -73,7 +73,7 @@
     ngx_array_t                   *cookie_domains;
     ngx_array_t                   *cookie_paths;
 
-    ngx_str_t                      method;
+    ngx_http_complex_value_t       method;
     ngx_str_t                      location;
     ngx_str_t                      url;
 
@@ -182,6 +182,8 @@
     void *conf);
 static char *ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
+static char *ngx_http_proxy_method(ngx_conf_t *cf, ngx_command_t *cmd,
+    void *conf);
 #if (NGX_HTTP_CACHE)
 static char *ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -380,9 +382,9 @@
 
     { ngx_string("proxy_method"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_str_slot,
+      ngx_http_proxy_method,
       NGX_HTTP_LOC_CONF_OFFSET,
-      offsetof(ngx_http_proxy_loc_conf_t, method),
+      0,
       NULL },
 
     { ngx_string("proxy_pass_request_headers"),
@@ -1159,8 +1161,10 @@
         /* HEAD was changed to GET to cache response */
         method = u->method;
 
-    } else if (plcf->method.len) {
-        method = plcf->method;
+    } else if (plcf->method.value.data) {
+        if (ngx_http_complex_value(r, &plcf->method, &method) != NGX_OK) {
+            return NGX_ERROR;
+        }
 
     } else {
         method = r->method_name;
@@ -3158,7 +3162,9 @@
 
 #endif
 
-    ngx_conf_merge_str_value(conf->method, prev->method, "");
+    if (conf->method.value.data == NULL) {
+        conf->method = prev->method;
+    }
 
     ngx_conf_merge_value(conf->upstream.pass_request_headers,
                               prev->upstream.pass_request_headers, 1);
@@ -4140,6 +4146,34 @@
 }
 
 
+static char *
+ngx_http_proxy_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_http_proxy_loc_conf_t *plcf = conf;
+
+    ngx_str_t                         *value;
+    ngx_http_compile_complex_value_t   ccv;
+
+    value = cf->args->elts;
+
+    if (plcf->method.value.data) {
+        return "is duplicate";
+    }
+
+    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+    ccv.cf = cf;
+    ccv.value = &value[1];
+    ccv.complex_value = &plcf->method;
+
+    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
+    return NGX_CONF_OK;
+}
+
+
 #if (NGX_HTTP_CACHE)
 
 static char *



More information about the nginx-devel mailing list