[nginx] Mirror: "off" paramater of the "mirror" directive.

Roman Arutyunyan arut at nginx.com
Fri Jul 21 19:12:52 UTC 2017


details:   http://hg.nginx.org/nginx/rev/230d16d35ebc
branches:  
changeset: 7073:230d16d35ebc
user:      Roman Arutyunyan <arut at nginx.com>
date:      Fri Jul 21 19:47:56 2017 +0300
description:
Mirror: "off" paramater of the "mirror" directive.

diffstat:

 src/http/modules/ngx_http_mirror_module.c |  45 +++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 2 deletions(-)

diffs (70 lines):

diff -r 0bb747b2d7cb -r 230d16d35ebc src/http/modules/ngx_http_mirror_module.c
--- a/src/http/modules/ngx_http_mirror_module.c	Thu Jul 20 08:50:49 2017 +0300
+++ b/src/http/modules/ngx_http_mirror_module.c	Fri Jul 21 19:47:56 2017 +0300
@@ -27,6 +27,7 @@ static ngx_int_t ngx_http_mirror_handler
 static void *ngx_http_mirror_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
+static char *ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 static ngx_int_t ngx_http_mirror_init(ngx_conf_t *cf);
 
 
@@ -34,9 +35,9 @@ static ngx_command_t  ngx_http_mirror_co
 
     { ngx_string("mirror"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
-      ngx_conf_set_str_array_slot,
+      ngx_http_mirror,
       NGX_HTTP_LOC_CONF_OFFSET,
-      offsetof(ngx_http_mirror_loc_conf_t, mirror),
+      0,
       NULL },
 
     { ngx_string("mirror_request_body"),
@@ -204,6 +205,46 @@ ngx_http_mirror_merge_loc_conf(ngx_conf_
 }
 
 
+static char *
+ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_http_mirror_loc_conf_t *mlcf = conf;
+
+    ngx_str_t  *value, *s;
+
+    value = cf->args->elts;
+
+    if (ngx_strcmp(value[1].data, "off") == 0) {
+        if (mlcf->mirror != NGX_CONF_UNSET_PTR) {
+            return "is duplicate";
+        }
+
+        mlcf->mirror = NULL;
+        return NGX_CONF_OK;
+    }
+
+    if (mlcf->mirror == NULL) {
+        return "is duplicate";
+    }
+
+    if (mlcf->mirror == NGX_CONF_UNSET_PTR) {
+        mlcf->mirror = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
+        if (mlcf->mirror == NULL) {
+            return NGX_CONF_ERROR;
+        }
+    }
+
+    s = ngx_array_push(mlcf->mirror);
+    if (s == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    *s = value[1];
+
+    return NGX_CONF_OK;
+}
+
+
 static ngx_int_t
 ngx_http_mirror_init(ngx_conf_t *cf)
 {


More information about the nginx-devel mailing list