diff options
| author | Andrei Belov <defan@nginx.com> | 2020-04-16 18:27:26 +0300 |
|---|---|---|
| committer | Andrei Belov <defan@nginx.com> | 2020-04-16 18:27:26 +0300 |
| commit | 74f32d26b91f49d3392605e81c1597b375890b60 (patch) | |
| tree | adfc67dfc86461441bde65512f745ce27bd6ea28 /src/nxt_http_return.c | |
| parent | 2ff9df10ef1df43c935c870175e52473dad2c21a (diff) | |
| parent | 9877087756144d3bdf343d0d4e91e1efbcc62c93 (diff) | |
| download | unit-74f32d26b91f49d3392605e81c1597b375890b60.tar.gz unit-74f32d26b91f49d3392605e81c1597b375890b60.tar.bz2 | |
Merged with the default branch.1.17.0-1
Diffstat (limited to 'src/nxt_http_return.c')
| -rw-r--r-- | src/nxt_http_return.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c new file mode 100644 index 00000000..c466cc25 --- /dev/null +++ b/src/nxt_http_return.c @@ -0,0 +1,57 @@ + +/* + * 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_field_t *field; + 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; + + if (action->name.length > 0) { + field = nxt_list_zero_add(r->resp.fields); + if (nxt_slow_path(field == NULL)) { + nxt_http_request_error(task, r, NXT_HTTP_INTERNAL_SERVER_ERROR); + return NULL; + } + + nxt_http_field_name_set(field, "Location"); + + field->value = action->name.start; + field->value_length = action->name.length; + } + + 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, +}; |
