summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_return.c
blob: c466cc2514e50855e7a60bb7e11dbd42bbad8e96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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,
};