comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 6:80ba094c6b3e NGINX_0_1_3

nginx 0.1.3 *) Feature: the ngx_http_autoindex_module and the autoindex directive. *) Feature: the proxy_set_x_url directive. *) Bugfix: proxy module may get caught in an endless loop when sendfile is not used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 25 Oct 2004 00:00:00 +0400
parents 4b2dafa26fe2
children 46833bd150cb
comparison
equal deleted inserted replaced
5:985c56ebe724 6:80ba094c6b3e
41 }; 41 };
42 42
43 43
44 static char http_version[] = " HTTP/1.0" CRLF; 44 static char http_version[] = " HTTP/1.0" CRLF;
45 static char host_header[] = "Host: "; 45 static char host_header[] = "Host: ";
46 static char x_url_header[] = "X-URL: http";
46 static char x_real_ip_header[] = "X-Real-IP: "; 47 static char x_real_ip_header[] = "X-Real-IP: ";
47 static char x_forwarded_for_header[] = "X-Forwarded-For: "; 48 static char x_forwarded_for_header[] = "X-Forwarded-For: ";
48 static char connection_close_header[] = "Connection: close" CRLF; 49 static char connection_close_header[] = "Connection: close" CRLF;
49 50
50 51
140 } else { 141 } else {
141 escape = 0; 142 escape = 0;
142 } 143 }
143 144
144 len += uc->uri.len 145 len += uc->uri.len
145 + r->uri.len - uc->location->len + escape 146 + r->uri.len - uc->location->len + escape
146 + 1 + r->args.len /* 1 is for "?" */ 147 + 1 + r->args.len /* 1 is for "?" */
147 + sizeof(http_version) - 1 148 + sizeof(http_version) - 1
148 + sizeof(connection_close_header) - 1 149 + sizeof(connection_close_header) - 1
149 + 2; /* 2 is for "\r\n" at the header end */ 150 + 2; /* 2 is for "\r\n" at the header end */
151
152
153 if (p->lcf->set_x_url) {
154 len += sizeof(x_url_header) - 1
155 + 4 /* 4 is for "s://" */
156 + r->port_text->len
157 + r->unparsed_uri.len
158 + 2; /* 2 is for "\r\n" at the header end */
159
160 if (r->headers_in.host) {
161 len += r->headers_in.host_name_len;
162
163 } else {
164 len += r->server_name.len;
165 }
166
167 }
168
150 169
151 if (p->lcf->preserve_host && r->headers_in.host) { 170 if (p->lcf->preserve_host && r->headers_in.host) {
152 len += sizeof(host_header) - 1 171 len += sizeof(host_header) - 1
153 + r->headers_in.host_name_len 172 + r->headers_in.host_name_len
154 + 1 /* 1 is for ":" */ 173 + 1 /* 1 is for ":" */
155 + uc->port_text.len 174 + uc->port_text.len
156 + 2; /* 2 is for "\r\n" */ 175 + 2; /* 2 is for "\r\n" */
157 } else { /* 2 is for "\r\n" */ 176 } else { /* 2 is for "\r\n" */
158 len += sizeof(host_header) - 1 + uc->host_header.len + 2; 177 len += sizeof(host_header) - 1 + uc->host_header.len + 2;
159 } 178 }
160 179
161 180
165 184
166 185
167 if (p->lcf->add_x_forwarded_for) { 186 if (p->lcf->add_x_forwarded_for) {
168 if (r->headers_in.x_forwarded_for) { 187 if (r->headers_in.x_forwarded_for) {
169 len += sizeof(x_forwarded_for_header) - 1 188 len += sizeof(x_forwarded_for_header) - 1
170 + r->headers_in.x_forwarded_for->value.len 189 + r->headers_in.x_forwarded_for->value.len
171 + 2 /* 2 is ofr ", " */ 190 + 2 /* 2 is ofr ", " */
172 + INET_ADDRSTRLEN - 1 191 + INET_ADDRSTRLEN - 1
173 + 2; /* 2 is for "\r\n" */ 192 + 2; /* 2 is for "\r\n" */
174 } else { 193 } else {
175 len += sizeof(x_forwarded_for_header) - 1 + INET_ADDRSTRLEN - 1 + 2; 194 len += sizeof(x_forwarded_for_header) - 1 + INET_ADDRSTRLEN - 1 + 2;
176 /* 2 is for "\r\n" */ 195 /* 2 is for "\r\n" */
177 } 196 }
178 } 197 }
269 uc->host_header.len); 288 uc->host_header.len);
270 } 289 }
271 *(b->last++) = CR; *(b->last++) = LF; 290 *(b->last++) = CR; *(b->last++) = LF;
272 291
273 292
293 /* the "X-URL" header */
294
295 if (p->lcf->set_x_url) {
296
297 b->last = ngx_cpymem(b->last, x_url_header,
298 sizeof(x_url_header) - 1);
299
300 #if (NGX_OPENSSL)
301
302 if (r->connection->ssl) {
303 *(b->last++) = 's';
304 }
305
306 #endif
307
308 *(b->last++) = ':'; *(b->last++) = '/'; *(b->last++) = '/';
309
310 if (r->headers_in.host) {
311 b->last = ngx_cpymem(b->last, r->headers_in.host->value.data,
312 r->headers_in.host_name_len);
313 } else {
314 b->last = ngx_cpymem(b->last, r->server_name.data,
315 r->server_name.len);
316 }
317
318 b->last = ngx_cpymem(b->last, r->port_text->data, r->port_text->len);
319 b->last = ngx_cpymem(b->last, r->unparsed_uri.data,
320 r->unparsed_uri.len);
321
322 *(b->last++) = CR; *(b->last++) = LF;
323 }
324
325
274 /* the "X-Real-IP" header */ 326 /* the "X-Real-IP" header */
275 327
276 if (p->lcf->set_x_real_ip) { 328 if (p->lcf->set_x_real_ip) {
277 b->last = ngx_cpymem(b->last, x_real_ip_header, 329 b->last = ngx_cpymem(b->last, x_real_ip_header,
278 sizeof(x_real_ip_header) - 1); 330 sizeof(x_real_ip_header) - 1);
334 } 386 }
335 387
336 if (&header[i] == r->headers_in.x_forwarded_for 388 if (&header[i] == r->headers_in.x_forwarded_for
337 && p->lcf->add_x_forwarded_for) 389 && p->lcf->add_x_forwarded_for)
338 { 390 {
391 continue;
392 }
393
394 if (&header[i] == r->headers_in.x_real_ip && p->lcf->set_x_real_ip) {
395 continue;
396 }
397
398 if (&header[i] == r->headers_in.x_url && p->lcf->set_x_url) {
339 continue; 399 continue;
340 } 400 }
341 401
342 b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len); 402 b->last = ngx_cpymem(b->last, header[i].key.data, header[i].key.len);
343 403