From 5f9c4754cbb1dfec0156b4473d1b31a4da8a3e3d Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 27 Mar 2020 17:22:52 +0300 Subject: Initialization of the action object made more consistent. --- src/nxt_http_route.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nxt_http_route.c') diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index d7f20bcb..ffa5f6e7 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -432,8 +432,6 @@ nxt_http_route_match_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, return NULL; } - match->action.u.route = NULL; - match->action.handler = NULL; match->items = n; action_conf = nxt_conf_get_path(cv, &action_path); @@ -613,6 +611,8 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, return ret; } + nxt_memzero(action, sizeof(nxt_http_action_t)); + conf = accf.pass; if (accf.share != NULL) { @@ -633,7 +633,7 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, } if (accf.fallback != NULL) { - action->u.fallback = nxt_mp_zalloc(mp, sizeof(nxt_http_action_t)); + action->u.fallback = nxt_mp_alloc(mp, sizeof(nxt_http_action_t)); if (nxt_slow_path(action->u.fallback == NULL)) { return NXT_ERROR; } -- cgit From 8d727774e3a2b2eaf194781c382fb953ed61f755 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 27 Mar 2020 17:22:52 +0300 Subject: Implemented "return" action. The "return" action can be used to immediately generate a simple HTTP response with an arbitrary status: { "action": { "return": 404 } } This is especially useful for denying access to specific resources. --- src/nxt_http_route.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nxt_http_route.c') diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index ffa5f6e7..6403a005 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -41,6 +41,7 @@ typedef enum { typedef struct { nxt_conf_value_t *pass; + nxt_conf_value_t *ret; nxt_conf_value_t *share; nxt_conf_value_t *proxy; nxt_conf_value_t *fallback; @@ -575,6 +576,11 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = { NXT_CONF_MAP_PTR, offsetof(nxt_http_route_action_conf_t, pass) }, + { + nxt_string("return"), + NXT_CONF_MAP_PTR, + offsetof(nxt_http_route_action_conf_t, ret) + }, { nxt_string("share"), NXT_CONF_MAP_PTR, @@ -613,6 +619,12 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, nxt_memzero(action, sizeof(nxt_http_action_t)); + if (accf.ret != NULL) { + action->handler = nxt_http_return_handler; + action->u.return_code = nxt_conf_get_integer(accf.ret); + return NXT_OK; + } + conf = accf.pass; if (accf.share != NULL) { -- cgit From c63b498f9416d26c1288a86ae4fc0b6007a16142 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Sat, 21 Mar 2020 01:39:00 +0300 Subject: Implemented "location" option for "return" action. This allows to specify redirects: { "action": { "return": 301, "location": "https://www.example.com/" } } --- src/nxt_http_route.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/nxt_http_route.c') diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 6403a005..ee22f48d 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -42,6 +42,7 @@ typedef enum { typedef struct { nxt_conf_value_t *pass; nxt_conf_value_t *ret; + nxt_str_t location; nxt_conf_value_t *share; nxt_conf_value_t *proxy; nxt_conf_value_t *fallback; @@ -581,6 +582,11 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = { NXT_CONF_MAP_PTR, offsetof(nxt_http_route_action_conf_t, ret) }, + { + nxt_string("location"), + NXT_CONF_MAP_STR, + offsetof(nxt_http_route_action_conf_t, location) + }, { nxt_string("share"), NXT_CONF_MAP_PTR, @@ -606,6 +612,7 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, nxt_mp_t *mp; nxt_int_t ret; nxt_str_t name, *string; + nxt_uint_t encode; nxt_conf_value_t *conf; nxt_http_route_action_conf_t accf; @@ -619,9 +626,38 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, nxt_memzero(action, sizeof(nxt_http_action_t)); + mp = tmcf->router_conf->mem_pool; + if (accf.ret != NULL) { action->handler = nxt_http_return_handler; action->u.return_code = nxt_conf_get_integer(accf.ret); + + if (accf.location.length > 0) { + if (nxt_is_complex_uri_encoded(accf.location.start, + accf.location.length)) + { + string = nxt_str_dup(mp, &action->name, &accf.location); + if (nxt_slow_path(string == NULL)) { + return NXT_ERROR; + } + + } else { + string = &action->name; + + encode = nxt_encode_complex_uri(NULL, accf.location.start, + accf.location.length); + string->length = accf.location.length + encode * 2; + + string->start = nxt_mp_nget(mp, string->length); + if (nxt_slow_path(string->start == NULL)) { + return NXT_ERROR; + } + + nxt_encode_complex_uri(string->start, accf.location.start, + accf.location.length); + } + } + return NXT_OK; } @@ -637,8 +673,6 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, nxt_conf_get_string(conf, &name); - mp = tmcf->router_conf->mem_pool; - string = nxt_str_dup(mp, &action->name, &name); if (nxt_slow_path(string == NULL)) { return NXT_ERROR; -- cgit From 68c6b67ffc840c78eddd27a65e9bf1370aaf5631 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 30 Mar 2020 19:37:58 +0300 Subject: Configuration: support for rational numbers. --- src/nxt_http_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nxt_http_route.c') diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index ee22f48d..ca43c060 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -630,7 +630,7 @@ nxt_http_route_action_create(nxt_router_temp_conf_t *tmcf, nxt_conf_value_t *cv, if (accf.ret != NULL) { action->handler = nxt_http_return_handler; - action->u.return_code = nxt_conf_get_integer(accf.ret); + action->u.return_code = nxt_conf_get_number(accf.ret); if (accf.location.length > 0) { if (nxt_is_complex_uri_encoded(accf.location.start, -- cgit