diff options
author | Valentin Bartenev <vbart@nginx.com> | 2020-03-21 01:39:00 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2020-03-21 01:39:00 +0300 |
commit | c63b498f9416d26c1288a86ae4fc0b6007a16142 (patch) | |
tree | 7fe911579cc7f3aac50a0a649236195127cf767e /src/nxt_http_return.c | |
parent | 35d6f84426cfaa27587456a8ebb81b13f60e697a (diff) | |
download | unit-c63b498f9416d26c1288a86ae4fc0b6007a16142.tar.gz unit-c63b498f9416d26c1288a86ae4fc0b6007a16142.tar.bz2 |
Implemented "location" option for "return" action.
This allows to specify redirects:
{
"action": {
"return": 301,
"location": "https://www.example.com/"
}
}
Diffstat (limited to 'src/nxt_http_return.c')
-rw-r--r-- | src/nxt_http_return.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/nxt_http_return.c b/src/nxt_http_return.c index 770f5289..c466cc25 100644 --- a/src/nxt_http_return.c +++ b/src/nxt_http_return.c @@ -14,6 +14,7 @@ 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; @@ -27,6 +28,20 @@ nxt_http_return_handler(nxt_task_t *task, nxt_http_request_t *r, 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); |