[PATCH] Add 'version' parameter for http upstream server directive

Kunal Pariani kpariani at zimbra.com
Wed Sep 17 22:59:23 UTC 2014


# HG changeset patch
# User Kunal Pariani <kpariani at zimbra.com>
# Date 1410994128 18000
#      Wed Sep 17 17:48:48 2014 -0500
# Node ID 1cad46e7189fc43d50a24735f61793f710f78967
# Parent  dfc11aa2a98e697a562b2aee092a77e3dc13f55a
Add 'version' parameter for http upstream server directive

diff -r dfc11aa2a98e -r 1cad46e7189f src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c	Wed Sep 17 15:42:10 2014 -0500
+++ b/src/http/ngx_http_upstream.c	Wed Sep 17 17:48:48 2014 -0500
@@ -4870,7 +4870,8 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_co
                                          |NGX_HTTP_UPSTREAM_MAX_FAILS
                                          |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
                                          |NGX_HTTP_UPSTREAM_DOWN
-                                         |NGX_HTTP_UPSTREAM_BACKUP);
+                                         |NGX_HTTP_UPSTREAM_BACKUP
+                                         |NGX_HTTP_UPSTREAM_VERSION);
     if (uscf == NULL) {
         return NGX_CONF_ERROR;
     }
@@ -4966,7 +4967,7 @@ ngx_http_upstream_server(ngx_conf_t *cf,
     ngx_http_upstream_srv_conf_t  *uscf = conf;
 
     time_t                       fail_timeout;
-    ngx_str_t                   *value, s;
+    ngx_str_t                   *value, s, version;
     ngx_url_t                    u;
     ngx_int_t                    weight, max_fails;
     ngx_uint_t                   i;
@@ -4984,6 +4985,8 @@ ngx_http_upstream_server(ngx_conf_t *cf,
     weight = 1;
     max_fails = 1;
     fail_timeout = 10;
+    version.len = 0;
+    version.data = NULL;
 
     for (i = 2; i < cf->args->nelts; i++) {
 
@@ -5057,6 +5060,20 @@ ngx_http_upstream_server(ngx_conf_t *cf,
             continue;
         }
 
+        if (ngx_strncmp(value[i].data, "version=", 8) == 0) {
+
+            if (!(uscf->flags & NGX_HTTP_UPSTREAM_VERSION)) {
+                goto invalid;
+            }
+
+            s.len = value[i].len - 8;
+            s.data = &value[i].data[8];
+
+            version = s;
+
+            continue;
+        }
+
         goto invalid;
     }
 
@@ -5080,6 +5097,7 @@ ngx_http_upstream_server(ngx_conf_t *cf,
     us->weight = weight;
     us->max_fails = max_fails;
     us->fail_timeout = fail_timeout;
+    us->version = version;
 
     return NGX_CONF_OK;
 
diff -r dfc11aa2a98e -r 1cad46e7189f src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h	Wed Sep 17 15:42:10 2014 -0500
+++ b/src/http/ngx_http_upstream.h	Wed Sep 17 17:48:48 2014 -0500
@@ -93,6 +93,7 @@ typedef struct {
     ngx_uint_t                       weight;
     ngx_uint_t                       max_fails;
     time_t                           fail_timeout;
+    ngx_str_t                        version;
 
     unsigned                         down:1;
     unsigned                         backup:1;
@@ -105,6 +106,7 @@ typedef struct {
 #define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT  0x0008
 #define NGX_HTTP_UPSTREAM_DOWN          0x0010
 #define NGX_HTTP_UPSTREAM_BACKUP        0x0020
+#define NGX_HTTP_UPSTREAM_VERSION       0x0040
 
 
 struct ngx_http_upstream_srv_conf_s {



More information about the nginx-devel mailing list