1431Sigor@sysoev.ru
2431Sigor@sysoev.ru /*
3431Sigor@sysoev.ru * Copyright (C) Igor Sysoev
4431Sigor@sysoev.ru * Copyright (C) NGINX, Inc.
5431Sigor@sysoev.ru */
6431Sigor@sysoev.ru
7431Sigor@sysoev.ru #include <nxt_router.h>
8431Sigor@sysoev.ru #include <nxt_http.h>
9431Sigor@sysoev.ru
10431Sigor@sysoev.ru
11431Sigor@sysoev.ru static nxt_int_t nxt_http_response_status(void *ctx, nxt_http_field_t *field,
12431Sigor@sysoev.ru uintptr_t data);
13431Sigor@sysoev.ru static nxt_int_t nxt_http_response_skip(void *ctx, nxt_http_field_t *field,
14431Sigor@sysoev.ru uintptr_t data);
15431Sigor@sysoev.ru static nxt_int_t nxt_http_response_field(void *ctx, nxt_http_field_t *field,
16431Sigor@sysoev.ru uintptr_t offset);
17431Sigor@sysoev.ru
18431Sigor@sysoev.ru
19431Sigor@sysoev.ru nxt_lvlhsh_t nxt_response_fields_hash;
20431Sigor@sysoev.ru
21431Sigor@sysoev.ru static nxt_http_field_proc_t nxt_response_fields[] = {
22431Sigor@sysoev.ru { nxt_string("Status"), &nxt_http_response_status, 0 },
23431Sigor@sysoev.ru { nxt_string("Server"), &nxt_http_response_skip, 0 },
24543Svbart@nginx.com { nxt_string("Date"), &nxt_http_response_field,
25543Svbart@nginx.com offsetof(nxt_http_request_t, resp.date) },
26431Sigor@sysoev.ru { nxt_string("Connection"), &nxt_http_response_skip, 0 },
27431Sigor@sysoev.ru { nxt_string("Content-Type"), &nxt_http_response_field,
28431Sigor@sysoev.ru offsetof(nxt_http_request_t, resp.content_type) },
29431Sigor@sysoev.ru { nxt_string("Content-Length"), &nxt_http_response_field,
30431Sigor@sysoev.ru offsetof(nxt_http_request_t, resp.content_length) },
311131Smax.romanov@nginx.com { nxt_string("Upgrade"), &nxt_http_response_skip, 0 },
321131Smax.romanov@nginx.com { nxt_string("Sec-WebSocket-Accept"), &nxt_http_response_skip, 0 },
33431Sigor@sysoev.ru };
34431Sigor@sysoev.ru
35431Sigor@sysoev.ru
36431Sigor@sysoev.ru nxt_int_t
nxt_http_response_hash_init(nxt_task_t * task)37*1459Smax.romanov@nginx.com nxt_http_response_hash_init(nxt_task_t *task)
38431Sigor@sysoev.ru {
39*1459Smax.romanov@nginx.com return nxt_http_fields_hash(&nxt_response_fields_hash,
40431Sigor@sysoev.ru nxt_response_fields, nxt_nitems(nxt_response_fields));
41431Sigor@sysoev.ru }
42431Sigor@sysoev.ru
43431Sigor@sysoev.ru
44431Sigor@sysoev.ru nxt_int_t
nxt_http_response_status(void * ctx,nxt_http_field_t * field,uintptr_t data)45431Sigor@sysoev.ru nxt_http_response_status(void *ctx, nxt_http_field_t *field,
46431Sigor@sysoev.ru uintptr_t data)
47431Sigor@sysoev.ru {
48431Sigor@sysoev.ru nxt_int_t status;
49431Sigor@sysoev.ru nxt_http_request_t *r;
50431Sigor@sysoev.ru
51431Sigor@sysoev.ru r = ctx;
52431Sigor@sysoev.ru
53431Sigor@sysoev.ru field->skip = 1;
54431Sigor@sysoev.ru
55431Sigor@sysoev.ru if (field->value_length >= 3) {
56431Sigor@sysoev.ru status = nxt_int_parse(field->value, 3);
57431Sigor@sysoev.ru
58431Sigor@sysoev.ru if (status >= 100 && status <= 999) {
59431Sigor@sysoev.ru r->status = status;
60431Sigor@sysoev.ru return NXT_OK;
61431Sigor@sysoev.ru }
62431Sigor@sysoev.ru }
63431Sigor@sysoev.ru
64431Sigor@sysoev.ru return NXT_ERROR;
65431Sigor@sysoev.ru }
66431Sigor@sysoev.ru
67431Sigor@sysoev.ru
68431Sigor@sysoev.ru nxt_int_t
nxt_http_response_skip(void * ctx,nxt_http_field_t * field,uintptr_t data)69431Sigor@sysoev.ru nxt_http_response_skip(void *ctx, nxt_http_field_t *field, uintptr_t data)
70431Sigor@sysoev.ru {
71431Sigor@sysoev.ru field->skip = 1;
72431Sigor@sysoev.ru
73431Sigor@sysoev.ru return NXT_OK;
74431Sigor@sysoev.ru }
75431Sigor@sysoev.ru
76431Sigor@sysoev.ru
77431Sigor@sysoev.ru nxt_int_t
nxt_http_response_field(void * ctx,nxt_http_field_t * field,uintptr_t offset)78431Sigor@sysoev.ru nxt_http_response_field(void *ctx, nxt_http_field_t *field, uintptr_t offset)
79431Sigor@sysoev.ru {
80431Sigor@sysoev.ru nxt_http_request_t *r;
81431Sigor@sysoev.ru
82431Sigor@sysoev.ru r = ctx;
83431Sigor@sysoev.ru
84431Sigor@sysoev.ru nxt_value_at(nxt_http_field_t *, r, offset) = field;
85431Sigor@sysoev.ru
86431Sigor@sysoev.ru return NXT_OK;
87431Sigor@sysoev.ru }
88