comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 294:5cfd65b8b0a7

nginx-0.0.3-2004-03-23-09:01:52 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 23 Mar 2004 06:01:52 +0000
parents ec3c049681fd
children ee394e997c77
comparison
equal deleted inserted replaced
293:ec3c049681fd 294:5cfd65b8b0a7
146 /* 2 is for "\r\n" */ 146 /* 2 is for "\r\n" */
147 } 147 }
148 } 148 }
149 149
150 150
151 header = (ngx_table_elt_t *) r->headers_in.headers->elts; 151 header = r->headers_in.headers.elts;
152 for (i = 0; i < r->headers_in.headers->nelts; i++) { 152 for (i = 0; i < r->headers_in.headers.nelts; i++) {
153 153
154 if (&header[i] == r->headers_in.host) { 154 if (&header[i] == r->headers_in.host) {
155 continue; 155 continue;
156 } 156 }
157 157
196 196
197 /* the "Host" header */ 197 /* the "Host" header */
198 198
199 h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1); 199 h->last = ngx_cpymem(h->last, host_header, sizeof(host_header) - 1);
200 200
201 if (p->lcf->preserve_host) { 201 if (p->lcf->preserve_host && r->headers_in.host) {
202 h->last = ngx_cpymem(h->last, r->headers_in.host->value.data, 202 h->last = ngx_cpymem(h->last, r->headers_in.host->value.data,
203 r->headers_in.host_name_len); 203 r->headers_in.host_name_len);
204 204
205 if (!uc->default_port) { 205 if (!uc->default_port) {
206 *(h->last++) = ':'; 206 *(h->last++) = ':';
248 r->connection->addr_text.len); 248 r->connection->addr_text.len);
249 *(h->last++) = CR; *(h->last++) = LF; 249 *(h->last++) = CR; *(h->last++) = LF;
250 } 250 }
251 251
252 252
253 for (i = 0; i < r->headers_in.headers->nelts; i++) { 253 for (i = 0; i < r->headers_in.headers.nelts; i++) {
254 254
255 if (&header[i] == r->headers_in.host) { 255 if (&header[i] == r->headers_in.host) {
256 continue; 256 continue;
257 } 257 }
258 258
375 if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) { 375 if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
376 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 376 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
377 return; 377 return;
378 } 378 }
379 379
380 output->output_ctx = writer; 380 output->filter_ctx = writer;
381 writer->pool = r->pool; 381 writer->pool = r->pool;
382 382
383 if (p->lcf->busy_lock && !p->busy_locked) { 383 if (p->lcf->busy_lock && !p->busy_locked) {
384 ngx_http_proxy_upstream_busy_lock(p); 384 ngx_http_proxy_upstream_busy_lock(p);
385 } else { 385 } else {
390 390
391 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p) 391 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
392 { 392 {
393 ngx_chain_t *cl; 393 ngx_chain_t *cl;
394 ngx_output_chain_ctx_t *output; 394 ngx_output_chain_ctx_t *output;
395 ngx_chain_writer_ctx_t *writer;
396 395
397 output = p->upstream->output_chain_ctx; 396 output = p->upstream->output_chain_ctx;
398 397
399 /* reinit the request chain */ 398 /* reinit the request chain */
400 399
401 for (cl = p->request->request_hunks; cl; cl = cl->next) { 400 for (cl = p->request->request_hunks; cl; cl = cl->next) {
402 cl->hunk->pos = cl->hunk->start; 401 cl->hunk->pos = cl->hunk->start;
402 cl->hunk->file_pos = 0;
403 } 403 }
404 404
405 /* reinit the ngx_output_chain() context */ 405 /* reinit the ngx_output_chain() context */
406 406
407 output->hunk = NULL; 407 output->hunk = NULL;
519 c->read->log = c->write->log = c->log = r->connection->log; 519 c->read->log = c->write->log = c->log = r->connection->log;
520 520
521 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ 521 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
522 522
523 output = p->upstream->output_chain_ctx; 523 output = p->upstream->output_chain_ctx;
524 writer = output->output_ctx; 524 writer = output->filter_ctx;
525 writer->out = NULL; 525 writer->out = NULL;
526 writer->last = &writer->out; 526 writer->last = &writer->out;
527 writer->connection = c; 527 writer->connection = c;
528 528
529 if (p->upstream->peer.tries > 1 && p->request_sent) { 529 if (p->upstream->peer.tries > 1 && p->request_sent) {
539 output->free->hunk = r->request_body_hunk; 539 output->free->hunk = r->request_body_hunk;
540 output->free->next = NULL; 540 output->free->next = NULL;
541 output->hunks = 1; 541 output->hunks = 1;
542 542
543 r->request_body_hunk->pos = r->request_body_hunk->start; 543 r->request_body_hunk->pos = r->request_body_hunk->start;
544 r->request_body_hunk->last = r->request_body_hunk->start;
545 } 544 }
546 545
547 p->request_sent = 0; 546 p->request_sent = 0;
548 547
549 if (rc == NGX_AGAIN) { 548 if (rc == NGX_AGAIN) {
822 821
823 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0, 822 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
824 "http proxy status %d \"%s\"", 823 "http proxy status %d \"%s\"",
825 p->upstream->status, p->upstream->status_line.data); 824 p->upstream->status, p->upstream->status_line.data);
826 825
827 if (p->upstream->headers_in.headers) { 826
828 p->upstream->headers_in.headers->nelts = 0; 827 /* init or reinit the p->upstream->headers_in.headers table */
828
829 if (p->upstream->headers_in.headers.elts) {
830 p->upstream->headers_in.headers.nelts = 0;
831
829 } else { 832 } else {
830 /* TODO: ngx_init_table */ 833 p->upstream->headers_in.headers.elts = ngx_pcalloc(p->request->pool,
831 p->upstream->headers_in.headers = ngx_create_table(p->request->pool, 834 20 * sizeof(ngx_table_elt_t));
832 20); 835 if (p->upstream->headers_in.headers.elts == NULL) {
833 } 836 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
837 return;
838 }
839 /* p->upstream->headers_in.headers.nelts = 0; */
840 p->upstream->headers_in.headers.nalloc = 20;
841 p->upstream->headers_in.headers.size = sizeof(ngx_table_elt_t);
842 p->upstream->headers_in.headers.pool = p->request->pool;
843 }
844
834 845
835 c->read->event_handler = ngx_http_proxy_process_upstream_headers; 846 c->read->event_handler = ngx_http_proxy_process_upstream_headers;
836 ngx_http_proxy_process_upstream_headers(rev); 847 ngx_http_proxy_process_upstream_headers(rev);
837 } 848 }
838 849