summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2019-05-30 15:33:51 +0300
committerIgor Sysoev <igor@sysoev.ru>2019-05-30 15:33:51 +0300
commit0ba7cfce7572070892bf54ed69b82a822e3ee0d4 (patch)
treee285a25d935a95118d051a29e87650d48a66a334 /src/nxt_conf_validation.c
parent3aaebe4169f80707e495f1111b7ab9c2dcb79b6d (diff)
downloadunit-0ba7cfce7572070892bf54ed69b82a822e3ee0d4.tar.gz
unit-0ba7cfce7572070892bf54ed69b82a822e3ee0d4.tar.bz2
Added routing based on header fields.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index aedcc605..bee82dd4 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -66,6 +66,12 @@ static nxt_int_t nxt_conf_vldt_match_patterns(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
static nxt_int_t nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value);
+static nxt_int_t nxt_conf_vldt_match_patterns_sets(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_match_patterns_set(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value);
+static nxt_int_t nxt_conf_vldt_match_patterns_set_member(
+ nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value);
static nxt_int_t nxt_conf_vldt_app_name(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
@@ -218,6 +224,21 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
&nxt_conf_vldt_match_patterns,
NULL },
+ { nxt_string("arguments"),
+ NXT_CONF_VLDT_OBJECT | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns_sets,
+ NULL },
+
+ { nxt_string("headers"),
+ NXT_CONF_VLDT_OBJECT | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns_sets,
+ NULL },
+
+ { nxt_string("cookies"),
+ NXT_CONF_VLDT_OBJECT | NXT_CONF_VLDT_ARRAY,
+ &nxt_conf_vldt_match_patterns_sets,
+ NULL },
+
NXT_CONF_VLDT_END
};
@@ -748,8 +769,8 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
} state;
if (nxt_conf_type(value) != NXT_CONF_STRING) {
- return nxt_conf_vldt_error(vldt,
- "The \"match\" patterns must be strings.");
+ return nxt_conf_vldt_error(vldt, "The \"match\" patterns for \"host\", "
+ "\"uri\", and \"method\" must be strings.");
}
nxt_conf_get_string(value, &pattern);
@@ -798,6 +819,49 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
}
+static nxt_int_t
+nxt_conf_vldt_match_patterns_sets(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ if (nxt_conf_type(value) == NXT_CONF_ARRAY) {
+ return nxt_conf_vldt_array_iterator(vldt, value,
+ &nxt_conf_vldt_match_patterns_set);
+ }
+
+ /* NXT_CONF_OBJECT */
+
+ return nxt_conf_vldt_match_patterns_set(vldt, value);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_match_patterns_set(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value)
+{
+ if (nxt_conf_type(value) != NXT_CONF_OBJECT) {
+ return nxt_conf_vldt_error(vldt, "The \"match\" patterns for "
+ "\"arguments\", \"cookies\", and "
+ "\"headers\" must be objects.");
+ }
+
+ return nxt_conf_vldt_object_iterator(vldt, value,
+ &nxt_conf_vldt_match_patterns_set_member);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_match_patterns_set_member(nxt_conf_validation_t *vldt,
+ nxt_str_t *name, nxt_conf_value_t *value)
+{
+ if (name->length == 0) {
+ return nxt_conf_vldt_error(vldt, "The \"match\" pattern objects must "
+ "not contain empty member names.");
+ }
+
+ return nxt_conf_vldt_match_patterns(vldt, value, NULL);
+}
+
+
#if (NXT_TLS)
static nxt_int_t