Mercurial > hg > nginx
comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 292:a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Mar 2004 21:26:01 +0000 |
parents | 117ccc7c4055 |
children | ec3c049681fd |
comparison
equal
deleted
inserted
replaced
291:117ccc7c4055 | 292:a472bfb778b3 |
---|---|
303 | 303 |
304 ngx_chain_t *cl; | 304 ngx_chain_t *cl; |
305 ngx_http_request_t *r; | 305 ngx_http_request_t *r; |
306 ngx_output_chain_ctx_t *output; | 306 ngx_output_chain_ctx_t *output; |
307 ngx_chain_writer_ctx_t *writer; | 307 ngx_chain_writer_ctx_t *writer; |
308 ngx_http_proxy_log_ctx_t *lctx; | 308 ngx_http_proxy_log_ctx_t *ctx; |
309 | 309 |
310 r = p->request; | 310 r = p->request; |
311 | 311 |
312 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 312 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
313 "http proxy set timer: %d", | 313 "http proxy set timer: %d", |
343 cl->next = r->request_hunks; | 343 cl->next = r->request_hunks; |
344 } | 344 } |
345 | 345 |
346 r->request_hunks = cl; | 346 r->request_hunks = cl; |
347 | 347 |
348 if (!(lctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) { | 348 if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) { |
349 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 349 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
350 return; | 350 return; |
351 } | 351 } |
352 lctx->connection = r->connection->number; | 352 ctx->connection = r->connection->number; |
353 lctx->proxy = p; | 353 ctx->proxy = p; |
354 | 354 |
355 p->upstream->peer.log = r->connection->log; | 355 p->upstream->peer.log = r->connection->log; |
356 p->saved_ctx = r->connection->log->data; | 356 p->saved_ctx = r->connection->log->data; |
357 p->saved_handler = r->connection->log->handler; | 357 p->saved_handler = r->connection->log->handler; |
358 r->connection->log->data = lctx; | 358 r->connection->log->data = ctx; |
359 r->connection->log->handler = ngx_http_proxy_log_error; | 359 r->connection->log->handler = ngx_http_proxy_log_error; |
360 p->action = "connecting to upstream"; | 360 p->action = "connecting to upstream"; |
361 | 361 |
362 if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) { | 362 if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) { |
363 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 363 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
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->output_ctx = writer; |
381 | |
382 writer->pool = r->pool; | 381 writer->pool = r->pool; |
383 | 382 |
384 if (p->lcf->busy_lock && !p->busy_locked) { | 383 if (p->lcf->busy_lock && !p->busy_locked) { |
385 ngx_http_proxy_upstream_busy_lock(p); | 384 ngx_http_proxy_upstream_busy_lock(p); |
386 } else { | 385 } else { |
391 | 390 |
392 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) |
393 { | 392 { |
394 ngx_chain_t *cl; | 393 ngx_chain_t *cl; |
395 ngx_output_chain_ctx_t *output; | 394 ngx_output_chain_ctx_t *output; |
395 ngx_chain_writer_ctx_t *writer; | |
396 | 396 |
397 output = p->upstream->output_chain_ctx; | 397 output = p->upstream->output_chain_ctx; |
398 | 398 |
399 /* reinit the request chain */ | 399 /* reinit the request chain */ |
400 | 400 |
401 for (cl = p->request->request_hunks; cl; cl = cl->next) { | 401 for (cl = p->request->request_hunks; cl; cl = cl->next) { |
402 cl->hunk->pos = cl->hunk->start; | 402 cl->hunk->pos = cl->hunk->start; |
403 } | 403 } |
404 | 404 |
405 /* reinit ngx_output_chain() context */ | 405 /* reinit the ngx_output_chain() context */ |
406 | 406 |
407 output->hunk = NULL; | 407 output->hunk = NULL; |
408 output->in = NULL; | 408 output->in = NULL; |
409 output->free = NULL; | 409 output->free = NULL; |
410 output->busy = NULL; | 410 output->busy = NULL; |
486 { | 486 { |
487 int rc; | 487 int rc; |
488 ngx_connection_t *c; | 488 ngx_connection_t *c; |
489 ngx_http_request_t *r; | 489 ngx_http_request_t *r; |
490 ngx_output_chain_ctx_t *output; | 490 ngx_output_chain_ctx_t *output; |
491 ngx_chain_writer_ctx_t *writer; | |
491 | 492 |
492 p->action = "connecting to upstream"; | 493 p->action = "connecting to upstream"; |
493 | 494 |
494 rc = ngx_event_connect_peer(&p->upstream->peer); | 495 rc = ngx_event_connect_peer(&p->upstream->peer); |
495 | 496 |
515 r = p->request; | 516 r = p->request; |
516 c = p->upstream->peer.connection; | 517 c = p->upstream->peer.connection; |
517 c->pool = r->pool; | 518 c->pool = r->pool; |
518 c->read->log = c->write->log = c->log = r->connection->log; | 519 c->read->log = c->write->log = c->log = r->connection->log; |
519 | 520 |
521 /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */ | |
522 | |
520 output = p->upstream->output_chain_ctx; | 523 output = p->upstream->output_chain_ctx; |
524 writer = output->output_ctx; | |
525 writer->out = NULL; | |
526 writer->last = &writer->out; | |
527 writer->connection = c; | |
521 | 528 |
522 if (p->upstream->peer.tries > 1 && p->request_sent) { | 529 if (p->upstream->peer.tries > 1 && p->request_sent) { |
523 ngx_http_proxy_reinit_upstream(p); | 530 ngx_http_proxy_reinit_upstream(p); |
524 } | 531 } |
525 | |
526 /* init or reinit ngx_output_chain() context */ | |
527 | 532 |
528 if (r->request_body_hunk) { | 533 if (r->request_body_hunk) { |
529 if (!(output->free = ngx_alloc_chain_link(r->pool))) { | 534 if (!(output->free = ngx_alloc_chain_link(r->pool))) { |
530 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); | 535 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); |
531 return; | 536 return; |
561 } | 566 } |
562 | 567 |
563 | 568 |
564 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) | 569 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) |
565 { | 570 { |
566 int rc; | 571 int rc; |
567 ngx_connection_t *c; | 572 ngx_connection_t *c; |
568 ngx_chain_writer_ctx_t *writer; | |
569 | 573 |
570 c = p->upstream->peer.connection; | 574 c = p->upstream->peer.connection; |
571 | 575 |
572 #if (HAVE_KQUEUE) | 576 #if (HAVE_KQUEUE) |
573 | 577 |
583 } | 587 } |
584 | 588 |
585 #endif | 589 #endif |
586 | 590 |
587 p->action = "sending request to upstream"; | 591 p->action = "sending request to upstream"; |
588 | |
589 writer = p->upstream->output_chain_ctx->output_ctx; | |
590 writer->out = NULL; | |
591 writer->last = &writer->out; | |
592 writer->connection = c; | |
593 | 592 |
594 rc = ngx_output_chain(p->upstream->output_chain_ctx, | 593 rc = ngx_output_chain(p->upstream->output_chain_ctx, |
595 p->request_sent ? NULL : p->request->request_hunks); | 594 p->request_sent ? NULL : p->request->request_hunks); |
596 | 595 |
597 if (rc == NGX_ERROR) { | 596 if (rc == NGX_ERROR) { |