summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nxt_conf_validation.c5
-rw-r--r--src/nxt_http.h1
-rw-r--r--src/nxt_http_route.c45
3 files changed, 51 insertions, 0 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 5d1cdf6d..3f068bbb 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -590,6 +590,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
.validator = nxt_conf_vldt_match_encoded_patterns,
.u.string = "uri"
}, {
+ .name = nxt_string("query"),
+ .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
+ .validator = nxt_conf_vldt_match_encoded_patterns,
+ .u.string = "query"
+ }, {
.name = nxt_string("arguments"),
.type = NXT_CONF_VLDT_OBJECT | NXT_CONF_VLDT_ARRAY,
.validator = nxt_conf_vldt_match_encoded_patterns_sets,
diff --git a/src/nxt_http.h b/src/nxt_http.h
index 332ac932..02d66f58 100644
--- a/src/nxt_http.h
+++ b/src/nxt_http.h
@@ -148,6 +148,7 @@ struct nxt_http_request_s {
nxt_str_t *path;
nxt_str_t *args;
+ nxt_str_t args_decoded;
nxt_array_t *arguments; /* of nxt_http_name_value_t */
nxt_array_t *cookies; /* of nxt_http_name_value_t */
nxt_list_t *fields;
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index b2df000f..606bf266 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -19,6 +19,7 @@ typedef enum {
NXT_HTTP_ROUTE_ARGUMENT,
NXT_HTTP_ROUTE_COOKIE,
NXT_HTTP_ROUTE_SCHEME,
+ NXT_HTTP_ROUTE_QUERY,
NXT_HTTP_ROUTE_SOURCE,
NXT_HTTP_ROUTE_DESTINATION,
} nxt_http_route_object_t;
@@ -54,6 +55,7 @@ typedef struct {
nxt_conf_value_t *arguments;
nxt_conf_value_t *cookies;
nxt_conf_value_t *scheme;
+ nxt_conf_value_t *query;
nxt_conf_value_t *source;
nxt_conf_value_t *destination;
} nxt_http_route_match_conf_t;
@@ -247,6 +249,8 @@ static nxt_int_t nxt_http_route_test_argument(nxt_http_request_t *r,
nxt_http_route_rule_t *rule, nxt_array_t *array);
static nxt_int_t nxt_http_route_scheme(nxt_http_request_t *r,
nxt_http_route_rule_t *rule);
+static nxt_int_t nxt_http_route_query(nxt_http_request_t *r,
+ nxt_http_route_rule_t *rule);
static nxt_int_t nxt_http_route_cookies(nxt_http_request_t *r,
nxt_http_route_rule_t *rule);
static nxt_array_t *nxt_http_route_cookies_parse(nxt_http_request_t *r);
@@ -366,6 +370,12 @@ static nxt_conf_map_t nxt_http_route_match_conf[] = {
},
{
+ nxt_string("query"),
+ NXT_CONF_MAP_PTR,
+ offsetof(nxt_http_route_match_conf_t, query),
+ },
+
+ {
nxt_string("source"),
NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_match_conf_t, source),
@@ -564,6 +574,19 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
test++;
}
+ if (mtcf.query != NULL) {
+ rule = nxt_http_route_rule_create(task, mp, mtcf.query, 1,
+ NXT_HTTP_ROUTE_PATTERN_NOCASE,
+ NXT_HTTP_ROUTE_ENCODING_URI_PLUS);
+ if (rule == NULL) {
+ return NULL;
+ }
+
+ rule->object = NXT_HTTP_ROUTE_QUERY;
+ test->rule = rule;
+ test++;
+ }
+
if (mtcf.source != NULL) {
addr_rule = nxt_http_route_addr_rule_create(task, mp, mtcf.source);
if (addr_rule == NULL) {
@@ -1776,6 +1799,9 @@ nxt_http_route_rule(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
case NXT_HTTP_ROUTE_SCHEME:
return nxt_http_route_scheme(r, rule);
+ case NXT_HTTP_ROUTE_QUERY:
+ return nxt_http_route_query(r, rule);
+
default:
break;
}
@@ -2045,6 +2071,8 @@ nxt_http_route_arguments_parse(nxt_http_request_t *r)
return NULL;
}
+ r->args_decoded.start = dst_start;
+
start = r->args->start;
end = start + r->args->length;
@@ -2105,6 +2133,8 @@ nxt_http_route_arguments_parse(nxt_http_request_t *r)
}
}
+ r->args_decoded.length = dst - r->args_decoded.start;
+
if (name_length != 0 || dst != dst_start) {
nv = nxt_http_route_argument(args, name, name_length, hash, dst_start,
dst);
@@ -2201,6 +2231,21 @@ nxt_http_route_scheme(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
static nxt_int_t
+nxt_http_route_query(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
+{
+ nxt_array_t *arguments;
+
+ arguments = nxt_http_route_arguments_parse(r);
+ if (nxt_slow_path(arguments == NULL)) {
+ return -1;
+ }
+
+ return nxt_http_route_test_rule(r, rule, r->args_decoded.start,
+ r->args_decoded.length);
+}
+
+
+static nxt_int_t
nxt_http_route_cookies(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
{
nxt_array_t *cookies;