1 2 /* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7 #include <nxt_router.h> 8 #include <nxt_http.h> 9 10 11 static nxt_int_t nxt_http_response_status(void *ctx, nxt_http_field_t *field, 12 uintptr_t data); 13 static nxt_int_t nxt_http_response_skip(void *ctx, nxt_http_field_t *field, 14 uintptr_t data); 15 static nxt_int_t nxt_http_response_field(void *ctx, nxt_http_field_t *field, 16 uintptr_t offset); 17 18 19 nxt_lvlhsh_t nxt_response_fields_hash; 20 21 static nxt_http_field_proc_t nxt_response_fields[] = { 22 { nxt_string("Status"), &nxt_http_response_status, 0 }, 23 { nxt_string("Server"), &nxt_http_response_skip, 0 }, 24 { nxt_string("Date"), &nxt_http_response_field, 25 offsetof(nxt_http_request_t, resp.date) }, 26 { nxt_string("Connection"), &nxt_http_response_skip, 0 }, 27 { nxt_string("Content-Type"), &nxt_http_response_field, 28 offsetof(nxt_http_request_t, resp.content_type) }, 29 { nxt_string("Content-Length"), &nxt_http_response_field, 30 offsetof(nxt_http_request_t, resp.content_length) }, 31 }; 32 33 34 nxt_int_t 35 nxt_http_response_hash_init(nxt_task_t *task, nxt_runtime_t *rt) 36 { 37 return nxt_http_fields_hash(&nxt_response_fields_hash, rt->mem_pool, 38 nxt_response_fields, nxt_nitems(nxt_response_fields)); 39 } 40 41 42 nxt_int_t 43 nxt_http_response_status(void *ctx, nxt_http_field_t *field, 44 uintptr_t data) 45 { 46 nxt_int_t status; 47 nxt_http_request_t *r; 48 49 r = ctx; 50 51 field->skip = 1; 52 53 if (field->value_length >= 3) { 54 status = nxt_int_parse(field->value, 3); 55 56 if (status >= 100 && status <= 999) { 57 r->status = status; 58 return NXT_OK; 59 } 60 } 61 62 return NXT_ERROR; 63 } 64 65 66 nxt_int_t 67 nxt_http_response_skip(void *ctx, nxt_http_field_t *field, uintptr_t data) 68 { 69 field->skip = 1; 70 71 return NXT_OK; 72 } 73 74 75 nxt_int_t 76 nxt_http_response_field(void *ctx, nxt_http_field_t *field, uintptr_t offset) 77 { 78 nxt_http_request_t *r; 79 80 r = ctx; 81 82 nxt_value_at(nxt_http_field_t *, r, offset) = field; 83 84 return NXT_OK; 85 } 86