summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_route.c
diff options
context:
space:
mode:
authorAxel Duch <axel.duch@nginx.com>2019-07-24 13:47:35 +0300
committerAxel Duch <axel.duch@nginx.com>2019-07-24 13:47:35 +0300
commit7785c96c1aea16dee0ec17403fda01b4f5ba41b3 (patch)
tree9abd736f0cfbfd6bea13685b1849ca4565dd1ce8 /src/nxt_http_route.c
parentb1165d2edc99daf8eef0e092e4ed6dcee9bce252 (diff)
downloadunit-7785c96c1aea16dee0ec17403fda01b4f5ba41b3.tar.gz
unit-7785c96c1aea16dee0ec17403fda01b4f5ba41b3.tar.bz2
Added routing based on request scheme.
Scheme matches exact string “http” or “https”.
Diffstat (limited to 'src/nxt_http_route.c')
-rw-r--r--src/nxt_http_route.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index ade44666..0b665573 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -15,6 +15,7 @@ typedef enum {
NXT_HTTP_ROUTE_HEADER,
NXT_HTTP_ROUTE_ARGUMENT,
NXT_HTTP_ROUTE_COOKIE,
+ NXT_HTTP_ROUTE_SCHEME,
} nxt_http_route_object_t;
@@ -41,6 +42,7 @@ typedef struct {
nxt_conf_value_t *headers;
nxt_conf_value_t *arguments;
nxt_conf_value_t *cookies;
+ nxt_conf_value_t *scheme;
} nxt_http_route_match_conf_t;
@@ -197,6 +199,8 @@ static nxt_http_name_value_t *nxt_http_route_argument(nxt_array_t *array,
u_char *end);
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_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);
@@ -277,6 +281,11 @@ nxt_http_routes_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
static nxt_conf_map_t nxt_http_route_match_conf[] = {
{
+ nxt_string("scheme"),
+ NXT_CONF_MAP_PTR,
+ offsetof(nxt_http_route_match_conf_t, scheme)
+ },
+ {
nxt_string("host"),
NXT_CONF_MAP_PTR,
offsetof(nxt_http_route_match_conf_t, host),
@@ -412,6 +421,18 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
test = &match->test[0];
+ if (mtcf.scheme != NULL) {
+ rule = nxt_http_route_rule_create(task, mp, mtcf.scheme, 1,
+ NXT_HTTP_ROUTE_PATTERN_NOCASE);
+ if (rule == NULL) {
+ return NULL;
+ }
+
+ rule->object = NXT_HTTP_ROUTE_SCHEME;
+ test->rule = rule;
+ test++;
+ }
+
if (mtcf.host != NULL) {
rule = nxt_http_route_rule_create(task, mp, mtcf.host, 1,
NXT_HTTP_ROUTE_PATTERN_LOWCASE);
@@ -1125,6 +1146,9 @@ nxt_http_route_rule(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
case NXT_HTTP_ROUTE_COOKIE:
return nxt_http_route_cookies(r, rule);
+ case NXT_HTTP_ROUTE_SCHEME:
+ return nxt_http_route_scheme(r, rule);
+
default:
break;
}
@@ -1331,6 +1355,18 @@ nxt_http_route_test_argument(nxt_http_request_t *r,
static nxt_int_t
+nxt_http_route_scheme(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
+{
+ nxt_bool_t tls, https;
+
+ https = (rule->pattern[0].length1 == nxt_length("https"));
+ tls = (r->tls != NULL);
+
+ return (tls == https);
+}
+
+
+static nxt_int_t
nxt_http_route_cookies(nxt_http_request_t *r, nxt_http_route_rule_t *rule)
{
nxt_array_t *cookies;