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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#include <nxt_router.h>
#include <nxt_http.h>
static nxt_int_t nxt_http_response_status(void *ctx, nxt_http_field_t *field,
uintptr_t data);
static nxt_int_t nxt_http_response_skip(void *ctx, nxt_http_field_t *field,
uintptr_t data);
static nxt_int_t nxt_http_response_field(void *ctx, nxt_http_field_t *field,
uintptr_t offset);
nxt_lvlhsh_t nxt_response_fields_hash;
static nxt_http_field_proc_t nxt_response_fields[] = {
{ nxt_string("Status"), &nxt_http_response_status, 0 },
{ nxt_string("Server"), &nxt_http_response_skip, 0 },
{ nxt_string("Date"), &nxt_http_response_field,
offsetof(nxt_http_request_t, resp.date) },
{ nxt_string("Connection"), &nxt_http_response_skip, 0 },
{ nxt_string("Content-Type"), &nxt_http_response_field,
offsetof(nxt_http_request_t, resp.content_type) },
{ nxt_string("Content-Length"), &nxt_http_response_field,
offsetof(nxt_http_request_t, resp.content_length) },
{ nxt_string("Upgrade"), &nxt_http_response_skip, 0 },
{ nxt_string("Sec-WebSocket-Accept"), &nxt_http_response_skip, 0 },
};
nxt_int_t
nxt_http_response_hash_init(nxt_task_t *task)
{
return nxt_http_fields_hash(&nxt_response_fields_hash,
nxt_response_fields, nxt_nitems(nxt_response_fields));
}
nxt_int_t
nxt_http_response_status(void *ctx, nxt_http_field_t *field,
uintptr_t data)
{
nxt_int_t status;
nxt_http_request_t *r;
r = ctx;
field->skip = 1;
if (field->value_length >= 3) {
status = nxt_int_parse(field->value, 3);
if (status >= 100 && status <= 999) {
r->status = status;
return NXT_OK;
}
}
return NXT_ERROR;
}
nxt_int_t
nxt_http_response_skip(void *ctx, nxt_http_field_t *field, uintptr_t data)
{
field->skip = 1;
return NXT_OK;
}
nxt_int_t
nxt_http_response_field(void *ctx, nxt_http_field_t *field, uintptr_t offset)
{
nxt_http_request_t *r;
r = ctx;
nxt_value_at(nxt_http_field_t *, r, offset) = field;
return NXT_OK;
}
|