comparison src/http/ngx_http_headers.c @ 165:894a01c6aea3

nginx-0.0.1-2003-10-29-20:39:05 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 29 Oct 2003 17:39:05 +0000
parents
children edf29bb717da
comparison
equal deleted inserted replaced
164:84036764e215 165:894a01c6aea3
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_http.h>
5
6
7 ngx_http_header_t ngx_http_headers_in[] = {
8 { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
9 { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
10 { ngx_string("If-Modified-Since"),
11 offsetof(ngx_http_headers_in_t, if_modified_since) },
12 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
13
14 { ngx_string("Content-Length"),
15 offsetof(ngx_http_headers_in_t, content_length) },
16 { ngx_string("Accept-Encoding"),
17 offsetof(ngx_http_headers_in_t, accept_encoding) },
18 { ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
19 #if 0
20 { ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
21 #endif
22
23 { ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
24
25 { ngx_null_string, 0 }
26 };
27
28
29 ngx_http_header_t ngx_http_headers_out[] = {
30 { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
31 { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
32 { ngx_string("Content-Type"),
33 offsetof(ngx_http_headers_out_t, content_type) },
34 { ngx_string("Content-Length"),
35 offsetof(ngx_http_headers_out_t, content_length) },
36 { ngx_string("Content-Encoding"),
37 offsetof(ngx_http_headers_out_t, content_encoding) },
38 { ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
39 { ngx_string("Last-Modified"),
40 offsetof(ngx_http_headers_out_t, last_modified) },
41 { ngx_string("Accept-Ranges"),
42 offsetof(ngx_http_headers_out_t, accept_ranges) },
43
44 { ngx_null_string, 0 }
45 };
46
47
48 ngx_table_elt_t *ngx_http_add_header(void *header,
49 ngx_http_header_t *http_headers)
50 {
51 int i, j, nelts;
52 char *prev;
53 ngx_table_t *headers;
54 ngx_table_elt_t *h, *new;
55
56 headers = *(ngx_table_t **) header;
57
58 prev = headers->elts;
59 nelts = headers->nelts;
60
61 if (!(new = ngx_push_table(headers))) {
62 return NULL;
63 }
64
65 if (prev == headers->elts) {
66 return new;
67 }
68
69 /*
70 * When table is relocated we need to update pointers in r->headers_in,
71 * r->headers_out, etc. However this relocation should be very rare
72 * because we preallocate enough space for the number of the real world
73 * HTTP headers.
74 */
75
76 ngx_log_error(NGX_LOG_ALERT, headers->pool->log, 0,
77 "header table is small, %d elements", nelts);
78
79 h = headers->elts;
80 for (i = 0; i < nelts; i++) {
81 if (h[i].key.len == 0) {
82 continue;
83 }
84
85 for (j = 0; http_headers[j].name.len != 0; j++) {
86 if (http_headers[j].name.len != h[i].key.len) {
87 continue;
88 }
89
90 if (ngx_strcasecmp(http_headers[j].name.data, h[i].key.data) == 0) {
91 *((ngx_table_elt_t **)
92 ((char *) header + http_headers[j].offset)) = &h[i];
93 break;
94 }
95 }
96 }
97
98 return new;
99 }
100