]> git.kaiwu.me - nginx.git/commitdiff
Added the ngx_http_test_required_predicates() function.
authorVladimir Homutov <vl@nginx.com>
Thu, 17 Jan 2019 11:31:04 +0000 (14:31 +0300)
committerVladimir Homutov <vl@nginx.com>
Thu, 17 Jan 2019 11:31:04 +0000 (14:31 +0300)
In contrast to ngx_http_test_predicates(), it requires all values to be
non-empty and not equal to "0".

src/http/ngx_http_script.c
src/http/ngx_http_script.h

index 1a8773561794b131feb5a1bdef584b46362a9308..415388904cd1e590879c35e0d25a3e88511e05e4 100644 (file)
@@ -271,6 +271,34 @@ ngx_http_test_predicates(ngx_http_request_t *r, ngx_array_t *predicates)
 }
 
 
+ngx_int_t
+ngx_http_test_required_predicates(ngx_http_request_t *r,
+    ngx_array_t *predicates)
+{
+    ngx_str_t                  val;
+    ngx_uint_t                 i;
+    ngx_http_complex_value_t  *cv;
+
+    if (predicates == NULL) {
+        return NGX_OK;
+    }
+
+    cv = predicates->elts;
+
+    for (i = 0; i < predicates->nelts; i++) {
+        if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) {
+            return NGX_ERROR;
+        }
+
+        if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) {
+            return NGX_DECLINED;
+        }
+    }
+
+    return NGX_OK;
+}
+
+
 char *
 ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
index a5116d747617fde32cd410c686ac478f296e59a2..25bb6d73f50200f363f2fe9c24c5124a69ed7f00 100644 (file)
@@ -214,6 +214,8 @@ char *ngx_http_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
 
 ngx_int_t ngx_http_test_predicates(ngx_http_request_t *r,
     ngx_array_t *predicates);
+ngx_int_t ngx_http_test_required_predicates(ngx_http_request_t *r,
+    ngx_array_t *predicates);
 char *ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);