summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_route.c
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2021-11-05 22:56:34 +0800
committerZhidao HONG <z.hong@f5.com>2021-11-05 22:56:34 +0800
commitaee908bcbd6ae160ab8e470ea6a373148649968b (patch)
tree99baed6d733282fd4cb537478c9ebf7a4ed194a8 /src/nxt_http_route.c
parent1260add0f5cacd5849640f7ee335f3ace97ade2c (diff)
downloadunit-aee908bcbd6ae160ab8e470ea6a373148649968b.tar.gz
unit-aee908bcbd6ae160ab8e470ea6a373148649968b.tar.bz2
Router: matching query string support.
The "query" option matches decoded arguments, including plus ('+') to space (' '). Like "uri", it can be a string or an array of strings.
Diffstat (limited to 'src/nxt_http_route.c')
-rw-r--r--src/nxt_http_route.c45
1 files changed, 45 insertions, 0 deletions
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;