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_return.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_return.c')
| -rw-r--r-- | src/nxt_http_return.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c new file mode 100644 index 00000000..770f5289 --- /dev/null +++ b/src/nxt_http_return.c @@ -0,0 +1,42 @@ + +/* + * Copyright (C) NGINX, Inc. + */ + +#include <nxt_router.h> +#include <nxt_http.h> + + +static const nxt_http_request_state_t nxt_http_return_send_state; + + +nxt_http_action_t * +nxt_http_return_handler(nxt_task_t *task, nxt_http_request_t *r, + nxt_http_action_t *action) +{ + nxt_http_status_t status; + + status = action->u.return_code; + + if (status >= NXT_HTTP_BAD_REQUEST + && status <= NXT_HTTP_SERVER_ERROR_MAX) + { + nxt_http_request_error(task, r, status); + return NULL; + } + + r->status = status; + r->resp.content_length_n = 0; + r->state = &nxt_http_return_send_state; + + nxt_http_request_header_send(task, r, NULL, NULL); + + return NULL; +} + + +static const nxt_http_request_state_t nxt_http_return_send_state + nxt_aligned(64) = +{ + .error_handler = nxt_http_request_error_handler, +}; |
