comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 288:f81d075ad172

nginx-0.0.2-2004-03-14-23:46:25 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 14 Mar 2004 20:46:25 +0000
parents 35a6a9df2d25
children 87e73f067470
comparison
equal deleted inserted replaced
287:35a6a9df2d25 288:f81d075ad172
55 return NGX_HTTP_INTERNAL_SERVER_ERROR; 55 return NGX_HTTP_INTERNAL_SERVER_ERROR;
56 } 56 }
57 57
58 p->upstream = u; 58 p->upstream = u;
59 59
60 u->peer.log_error = NGX_ERROR_ERR;
60 u->peer.peers = p->lcf->peers; 61 u->peer.peers = p->lcf->peers;
61 u->peer.tries = p->lcf->peers->number; 62 u->peer.tries = p->lcf->peers->number;
62 63
63 u->method = r->method; 64 u->method = r->method;
64 65
111 len = http_methods[p->upstream->method - 1].len 112 len = http_methods[p->upstream->method - 1].len
112 + uc->uri.len 113 + uc->uri.len
113 + r->uri.len - uc->location->len 114 + r->uri.len - uc->location->len
114 + 1 + r->args.len /* 1 is for "?" */ 115 + 1 + r->args.len /* 1 is for "?" */
115 + sizeof(http_version) - 1 116 + sizeof(http_version) - 1
116 + sizeof(host_header) - 1 + uc->host_header.len + 2
117 /* 2 is for "\r\n" */
118 + sizeof(connection_close_header) - 1 117 + sizeof(connection_close_header) - 1
119 + 2; /* 2 is for "\r\n" at the header end */ 118 + 2; /* 2 is for "\r\n" at the header end */
120 119
121 if (p->lcf->set_x_real_ip) { 120
122 /* 2 is for "\r\n" */ 121 if (p->lcf->preserve_host) {
122 len += sizeof(host_header) - 1
123 + r->headers_in.host_name_len
124 + 1 /* 1 is for ":" */
125 + uc->port_text.len
126 + 2; /* 2 is for "\r\n" */
127 } else { /* 2 is for "\r\n" */
128 len += sizeof(host_header) - 1 + uc->host_header.len + 2;
129 }
130
131
132 if (p->lcf->set_x_real_ip) { /* 2 is for "\r\n" */
123 len += sizeof(x_real_ip_header) - 1 + INET_ADDRSTRLEN - 1 + 2; 133 len += sizeof(x_real_ip_header) - 1 + INET_ADDRSTRLEN - 1 + 2;
124 } 134 }
125 135
126 136
127 if (p->lcf->add_x_forwarded_for) { 137 if (p->lcf->add_x_forwarded_for) {
128 if (r->headers_in.x_forwarded_for) { 138 if (r->headers_in.x_forwarded_for) {
129 len += r->headers_in.x_forwarded_for->key.len 139 len += sizeof(x_forwarded_for_header) - 1
130 + 2 /* 2 is ofr ": " */
131 + r->headers_in.x_forwarded_for->value.len 140 + r->headers_in.x_forwarded_for->value.len
132 + 2 /* 2 is ofr ", " */ 141 + 2 /* 2 is ofr ", " */
133 + INET_ADDRSTRLEN - 1 142 + INET_ADDRSTRLEN - 1
134 + 2; /* 2 is for "\r\n" */ 143 + 2; /* 2 is for "\r\n" */
135 } else { 144 } else {
177 } 186 }
178 187
179 h->last = ngx_cpymem(h->last, http_version, sizeof(http_version) - 1); 188 h->last = ngx_cpymem(h->last, http_version, sizeof(http_version) - 1);
180 189
181 190
182 /* the "Host" header */
183
184 h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
185 h->last = ngx_cpymem(h->last, uc->host_header.data, uc->host_header.len);
186 *(h->last++) = CR; *(h->last++) = LF;
187
188
189 /* the "Connection: close" header */ 191 /* the "Connection: close" header */
190 192
191 h->last = ngx_cpymem(h->last, connection_close_header, 193 h->last = ngx_cpymem(h->last, connection_close_header,
192 sizeof(connection_close_header) - 1); 194 sizeof(connection_close_header) - 1);
195
196
197 /* the "Host" header */
198
199 h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
200
201 if (p->lcf->preserve_host) {
202 h->last = ngx_cpymem(h->last, r->headers_in.host->value.data,
203 r->headers_in.host_name_len);
204
205 if (!uc->default_port) {
206 *(h->last++) = ':';
207 h->last = ngx_cpymem(h->last, uc->port_text.data,
208 uc->port_text.len);
209 }
210
211 } else {
212 h->last = ngx_cpymem(h->last, uc->host_header.data,
213 uc->host_header.len);
214 }
215 *(h->last++) = CR; *(h->last++) = LF;
193 216
194 217
195 /* the "X-Real-IP" header */ 218 /* the "X-Real-IP" header */
196 219
197 if (p->lcf->set_x_real_ip) { 220 if (p->lcf->set_x_real_ip) {
205 228
206 /* the "X-Forwarded-For" header */ 229 /* the "X-Forwarded-For" header */
207 230
208 if (p->lcf->add_x_forwarded_for) { 231 if (p->lcf->add_x_forwarded_for) {
209 if (r->headers_in.x_forwarded_for) { 232 if (r->headers_in.x_forwarded_for) {
210 h->last = ngx_cpymem(h->last, 233 h->last = ngx_cpymem(h->last, x_forwarded_for_header,
211 r->headers_in.x_forwarded_for->key.data, 234 sizeof(x_forwarded_for_header) - 1);
212 r->headers_in.x_forwarded_for->key.len);
213
214 *(h->last++) = ':'; *(h->last++) = ' ';
215 235
216 h->last = ngx_cpymem(h->last, 236 h->last = ngx_cpymem(h->last,
217 r->headers_in.x_forwarded_for->value.data, 237 r->headers_in.x_forwarded_for->value.data,
218 r->headers_in.x_forwarded_for->value.len); 238 r->headers_in.x_forwarded_for->value.len);
219 239
414 } 434 }
415 435
416 436
417 void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p) 437 void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
418 { 438 {
419 int rc, ft_type; 439 ngx_int_t rc;
440 #if (NGX_HTTP_CACHE)
441 ngx_int_t ft_type;
442 #endif
420 443
421 if (p->busy_lock.time == 0) { 444 if (p->busy_lock.time == 0) {
422 p->busy_lock.event = p->request->connection->read; 445 p->busy_lock.event = p->request->connection->read;
423 p->busy_lock.event_handler = ngx_http_proxy_busy_lock_handler; 446 p->busy_lock.event_handler = ngx_http_proxy_busy_lock_handler;
424 } 447 }
434 return; 457 return;
435 } 458 }
436 459
437 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); 460 ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
438 461
462 #if (NGX_HTTP_CACHE)
463
439 if (rc == NGX_DONE) { 464 if (rc == NGX_DONE) {
440 ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK; 465 ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
441 466
442 } else { 467 } else {
443 /* rc == NGX_ERROR */ 468 /* rc == NGX_ERROR */
444 ft_type = NGX_HTTP_PROXY_FT_MAX_WAITING; 469 ft_type = NGX_HTTP_PROXY_FT_MAX_WAITING;
445 } 470 }
446
447 #if (NGX_HTTP_CACHE)
448 471
449 if (p->stale && (p->lcf->use_stale & ft_type)) { 472 if (p->stale && (p->lcf->use_stale & ft_type)) {
450 ngx_http_proxy_finalize_request(p, 473 ngx_http_proxy_finalize_request(p,
451 ngx_http_proxy_send_cached_response(p)); 474 ngx_http_proxy_send_cached_response(p));
452 return; 475 return;
1065 ep->upstream = p->upstream->peer.connection; 1088 ep->upstream = p->upstream->peer.connection;
1066 ep->downstream = r->connection; 1089 ep->downstream = r->connection;
1067 ep->pool = r->pool; 1090 ep->pool = r->pool;
1068 ep->log = r->connection->log; 1091 ep->log = r->connection->log;
1069 1092
1093 ep->cachable = p->cachable;
1094
1070 if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) { 1095 if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
1071 ngx_http_proxy_finalize_request(p, 0); 1096 ngx_http_proxy_finalize_request(p, 0);
1072 return; 1097 return;
1073 } 1098 }
1074
1075 ep->cachable = p->cachable;
1076 1099
1077 ep->temp_file->file.fd = NGX_INVALID_FILE; 1100 ep->temp_file->file.fd = NGX_INVALID_FILE;
1078 ep->temp_file->file.log = r->connection->log; 1101 ep->temp_file->file.log = r->connection->log;
1079 ep->temp_file->path = p->lcf->temp_path; 1102 ep->temp_file->path = p->lcf->temp_path;
1080 ep->temp_file->pool = r->pool; 1103 ep->temp_file->pool = r->pool;