blob: 128744917d0962e7242562348bf89823d08a284e [file] [log] [blame]
Igor Sysoev14be46e2003-10-29 17:39:05 +00001
2#include <ngx_config.h>
3#include <ngx_core.h>
4#include <ngx_http.h>
5
6
7ngx_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) },
Igor Sysoev74e95c22003-11-09 20:03:38 +000013 { ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer) },
Igor Sysoev14be46e2003-10-29 17:39:05 +000014 { ngx_string("Content-Length"),
15 offsetof(ngx_http_headers_in_t, content_length) },
Igor Sysoev54498db2004-02-11 17:08:49 +000016
Igor Sysoev14be46e2003-10-29 17:39:05 +000017 { ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
18#if 0
19 { ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
20#endif
21
Igor Sysoev54498db2004-02-11 17:08:49 +000022 { ngx_string("Accept-Encoding"),
23 offsetof(ngx_http_headers_in_t, accept_encoding) },
24
Igor Sysoevcf80a702003-11-03 22:20:44 +000025 { ngx_string("Authorization"),
26 offsetof(ngx_http_headers_in_t, authorization) },
27
Igor Sysoev14be46e2003-10-29 17:39:05 +000028 { ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
29
30 { ngx_null_string, 0 }
31};
32
33
34ngx_http_header_t ngx_http_headers_out[] = {
35 { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
36 { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
37 { ngx_string("Content-Type"),
38 offsetof(ngx_http_headers_out_t, content_type) },
39 { ngx_string("Content-Length"),
40 offsetof(ngx_http_headers_out_t, content_length) },
41 { ngx_string("Content-Encoding"),
42 offsetof(ngx_http_headers_out_t, content_encoding) },
43 { ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
44 { ngx_string("Last-Modified"),
45 offsetof(ngx_http_headers_out_t, last_modified) },
46 { ngx_string("Accept-Ranges"),
47 offsetof(ngx_http_headers_out_t, accept_ranges) },
48
49 { ngx_null_string, 0 }
50};
51
52
53ngx_table_elt_t *ngx_http_add_header(void *header,
54 ngx_http_header_t *http_headers)
55{
Igor Sysoevfe0f5cc2003-10-31 16:05:33 +000056 int i, j;
Igor Sysoev14be46e2003-10-29 17:39:05 +000057 char *prev;
58 ngx_table_t *headers;
59 ngx_table_elt_t *h, *new;
60
61 headers = *(ngx_table_t **) header;
62
63 prev = headers->elts;
Igor Sysoev14be46e2003-10-29 17:39:05 +000064
65 if (!(new = ngx_push_table(headers))) {
66 return NULL;
67 }
68
69 if (prev == headers->elts) {
70 return new;
71 }
72
73 /*
74 * When table is relocated we need to update pointers in r->headers_in,
75 * r->headers_out, etc. However this relocation should be very rare
76 * because we preallocate enough space for the number of the real world
77 * HTTP headers.
78 */
79
80 ngx_log_error(NGX_LOG_ALERT, headers->pool->log, 0,
Igor Sysoevfe0f5cc2003-10-31 16:05:33 +000081 "header table is small, %d elements", headers->nelts - 1);
Igor Sysoev14be46e2003-10-29 17:39:05 +000082
83 h = headers->elts;
Igor Sysoevfe0f5cc2003-10-31 16:05:33 +000084 for (i = 0; i < headers->nelts - 1; i++) {
Igor Sysoev14be46e2003-10-29 17:39:05 +000085 if (h[i].key.len == 0) {
86 continue;
87 }
88
89 for (j = 0; http_headers[j].name.len != 0; j++) {
90 if (http_headers[j].name.len != h[i].key.len) {
91 continue;
92 }
93
94 if (ngx_strcasecmp(http_headers[j].name.data, h[i].key.data) == 0) {
95 *((ngx_table_elt_t **)
96 ((char *) header + http_headers[j].offset)) = &h[i];
97 break;
98 }
99 }
100 }
101
102 return new;
103}
104