Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/proxy/ngx_http_proxy_header.c @ 0:f0b350454894 NGINX_0_1_0
nginx 0.1.0
*) The first public version.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 04 Oct 2004 00:00:00 +0400 |
parents | |
children | cc9f381affaa |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0b350454894 |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 #include <ngx_http_proxy_handler.h> | |
11 | |
12 | |
13 static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, | |
14 ngx_table_elt_t *loc); | |
15 | |
16 int ngx_http_proxy_copy_header(ngx_http_proxy_ctx_t *p, | |
17 ngx_http_proxy_headers_in_t *headers_in) | |
18 { | |
19 ngx_uint_t i; | |
20 ngx_list_part_t *part; | |
21 ngx_table_elt_t *ho, *h; | |
22 ngx_http_request_t *r; | |
23 | |
24 r = p->request; | |
25 | |
26 part = &headers_in->headers.part; | |
27 h = part->elts; | |
28 | |
29 #if 0 | |
30 h = headers_in->headers.elts; | |
31 for (i = 0; i < headers_in->headers.nelts; i++) { | |
32 #endif | |
33 | |
34 for (i = 0 ; /* void */; i++) { | |
35 | |
36 if (i >= part->nelts) { | |
37 if (part->next == NULL) { | |
38 break; | |
39 } | |
40 | |
41 part = part->next; | |
42 h = part->elts; | |
43 i = 0; | |
44 } | |
45 | |
46 /* ignore some headers */ | |
47 | |
48 if (&h[i] == headers_in->connection) { | |
49 continue; | |
50 } | |
51 | |
52 if (&h[i] == headers_in->x_pad) { | |
53 continue; | |
54 } | |
55 | |
56 if (p->accel) { | |
57 if (&h[i] == headers_in->date | |
58 || &h[i] == headers_in->accept_ranges) { | |
59 continue; | |
60 } | |
61 | |
62 if (&h[i] == headers_in->x_accel_expires | |
63 && !p->lcf->pass_x_accel_expires) | |
64 { | |
65 continue; | |
66 } | |
67 | |
68 if (&h[i] == headers_in->server && !p->lcf->pass_server) { | |
69 continue; | |
70 } | |
71 | |
72 if (&h[i] == headers_in->location) { | |
73 if (ngx_http_proxy_rewrite_location_header(p, &h[i]) | |
74 == NGX_ERROR) | |
75 { | |
76 return NGX_ERROR; | |
77 } | |
78 | |
79 continue; | |
80 } | |
81 } | |
82 | |
83 | |
84 /* "Content-Type" is handled specially */ | |
85 | |
86 if (&h[i] == headers_in->content_type) { | |
87 r->headers_out.content_type = &h[i]; | |
88 r->headers_out.content_type->key.len = 0; | |
89 continue; | |
90 } | |
91 | |
92 | |
93 /* copy some header pointers and set up r->headers_out */ | |
94 | |
95 if (!(ho = ngx_list_push(&r->headers_out.headers))) { | |
96 return NGX_ERROR; | |
97 } | |
98 | |
99 *ho = h[i]; | |
100 | |
101 if (&h[i] == headers_in->expires) { | |
102 r->headers_out.expires = ho; | |
103 continue; | |
104 } | |
105 | |
106 if (&h[i] == headers_in->cache_control) { | |
107 r->headers_out.cache_control = ho; | |
108 continue; | |
109 } | |
110 | |
111 if (&h[i] == headers_in->etag) { | |
112 r->headers_out.etag = ho; | |
113 continue; | |
114 } | |
115 | |
116 if (&h[i] == headers_in->last_modified) { | |
117 r->headers_out.last_modified = ho; | |
118 /* TODO: update r->headers_out.last_modified_time */ | |
119 continue; | |
120 } | |
121 | |
122 /* | |
123 * ngx_http_header_filter() passes the following headers as is | |
124 * and does not handle them specially if they are set: | |
125 * r->headers_out.server, | |
126 * r->headers_out.date, | |
127 * r->headers_out.content_length | |
128 */ | |
129 | |
130 if (&h[i] == headers_in->server) { | |
131 r->headers_out.server = ho; | |
132 continue; | |
133 } | |
134 | |
135 if (&h[i] == headers_in->date) { | |
136 r->headers_out.date = ho; | |
137 continue; | |
138 } | |
139 | |
140 if (&h[i] == headers_in->content_length) { | |
141 r->headers_out.content_length = ho; | |
142 r->headers_out.content_length_n = ngx_atoi(ho->value.data, | |
143 ho->value.len); | |
144 continue; | |
145 } | |
146 } | |
147 | |
148 return NGX_OK; | |
149 } | |
150 | |
151 | |
152 static int ngx_http_proxy_rewrite_location_header(ngx_http_proxy_ctx_t *p, | |
153 ngx_table_elt_t *loc) | |
154 { | |
155 u_char *last; | |
156 ngx_table_elt_t *location; | |
157 ngx_http_request_t *r; | |
158 ngx_http_proxy_upstream_conf_t *uc; | |
159 | |
160 r = p->request; | |
161 uc = p->lcf->upstream; | |
162 | |
163 if (!(location = ngx_list_push(&r->headers_out.headers))) { | |
164 return NGX_ERROR; | |
165 } | |
166 | |
167 /* | |
168 * we do not set r->headers_out.location to avoid the handling | |
169 * the local redirects without a host name by ngx_http_header_filter() | |
170 */ | |
171 | |
172 #if 0 | |
173 r->headers_out.location = location; | |
174 #endif | |
175 | |
176 if (uc->url.len > loc->value.len | |
177 || ngx_rstrncmp(loc->value.data, uc->url.data, uc->url.len) != 0) | |
178 { | |
179 *location = *loc; | |
180 return NGX_OK; | |
181 } | |
182 | |
183 /* TODO: proxy_reverse */ | |
184 | |
185 location->value.len = uc->location->len | |
186 + (loc->value.len - uc->url.len) + 1; | |
187 if (!(location->value.data = ngx_palloc(r->pool, location->value.len))) { | |
188 return NGX_ERROR; | |
189 } | |
190 | |
191 last = ngx_cpymem(location->value.data, | |
192 uc->location->data, uc->location->len); | |
193 | |
194 ngx_cpystrn(last, loc->value.data + uc->url.len, | |
195 loc->value.len - uc->url.len + 1); | |
196 | |
197 return NGX_OK; | |
198 } |