Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 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) }, |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 13 | { ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer) }, |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 14 | { ngx_string("Content-Length"), |
| 15 | offsetof(ngx_http_headers_in_t, content_length) }, |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 16 | |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 17 | { 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 Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 22 | { ngx_string("Accept-Encoding"), |
| 23 | offsetof(ngx_http_headers_in_t, accept_encoding) }, |
| 24 | |
Igor Sysoev | cf80a70 | 2003-11-03 22:20:44 +0000 | [diff] [blame] | 25 | { ngx_string("Authorization"), |
| 26 | offsetof(ngx_http_headers_in_t, authorization) }, |
| 27 | |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 28 | { ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) }, |
| 29 | |
| 30 | { ngx_null_string, 0 } |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | ngx_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 | |
| 53 | ngx_table_elt_t *ngx_http_add_header(void *header, |
| 54 | ngx_http_header_t *http_headers) |
| 55 | { |
Igor Sysoev | fe0f5cc | 2003-10-31 16:05:33 +0000 | [diff] [blame] | 56 | int i, j; |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 57 | 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 Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 64 | |
| 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 Sysoev | fe0f5cc | 2003-10-31 16:05:33 +0000 | [diff] [blame] | 81 | "header table is small, %d elements", headers->nelts - 1); |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 82 | |
| 83 | h = headers->elts; |
Igor Sysoev | fe0f5cc | 2003-10-31 16:05:33 +0000 | [diff] [blame] | 84 | for (i = 0; i < headers->nelts - 1; i++) { |
Igor Sysoev | 14be46e | 2003-10-29 17:39:05 +0000 | [diff] [blame] | 85 | 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 | |