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.
This commit is contained in:
Valentin Bartenev
2020-03-27 17:22:52 +03:00
parent 5f9c4754cb
commit 8d727774e3
5 changed files with 96 additions and 4 deletions

View File

@@ -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) {