diff options
author | Valentin Bartenev <vbart@nginx.com> | 2020-03-27 17:22:52 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2020-03-27 17:22:52 +0300 |
commit | 8d727774e3a2b2eaf194781c382fb953ed61f755 (patch) | |
tree | 9c3ec0878ebffb033f352f59c7abc099d17307a9 /src/nxt_http_route.c | |
parent | 5f9c4754cbb1dfec0156b4473d1b31a4da8a3e3d (diff) | |
download | unit-8d727774e3a2b2eaf194781c382fb953ed61f755.tar.gz unit-8d727774e3a2b2eaf194781c382fb953ed61f755.tar.bz2 |
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.
Diffstat (limited to 'src/nxt_http_route.c')
-rw-r--r-- | src/nxt_http_route.c | 12 |
1 files changed, 12 insertions, 0 deletions
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; @@ -576,6 +577,11 @@ static nxt_conf_map_t nxt_http_route_action_conf[] = { 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, offsetof(nxt_http_route_action_conf_t, share) @@ -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) { |