comparison src/http/modules/proxy/ngx_http_proxy_upstream.c @ 291:117ccc7c4055

nginx-0.0.3-2004-03-16-16:35:20 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 16 Mar 2004 13:35:20 +0000
parents 87e73f067470
children a472bfb778b3
comparison
equal deleted inserted replaced
290:87e73f067470 291:117ccc7c4055
301 { 301 {
302 ngx_http_proxy_ctx_t *p = data; 302 ngx_http_proxy_ctx_t *p = data;
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 *octx; 306 ngx_output_chain_ctx_t *output;
307 ngx_chain_writer_ctx_t *wctx; 307 ngx_chain_writer_ctx_t *writer;
308 ngx_http_proxy_log_ctx_t *lctx; 308 ngx_http_proxy_log_ctx_t *lctx;
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,
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 = lctx;
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 (!(octx = 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);
364 return; 364 return;
365 } 365 }
366 366
367 p->upstream->output_chain_ctx = octx; 367 p->upstream->output_chain_ctx = output;
368 368
369 octx->sendfile = r->sendfile; 369 output->sendfile = r->sendfile;
370 octx->pool = r->pool; 370 output->pool = r->pool;
371 octx->bufs.num = 1; 371 output->bufs.num = 1;
372 octx->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module; 372 output->tag = (ngx_hunk_tag_t) &ngx_http_proxy_module;
373 octx->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer; 373 output->output_filter = (ngx_output_chain_filter_pt) ngx_chain_writer;
374 374
375 if (!(wctx = 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 octx->output_ctx = wctx; 380 output->output_ctx = writer;
381 381
382 wctx->pool = r->pool; 382 writer->pool = r->pool;
383 383
384 if (p->lcf->busy_lock && !p->busy_locked) { 384 if (p->lcf->busy_lock && !p->busy_locked) {
385 ngx_http_proxy_upstream_busy_lock(p); 385 ngx_http_proxy_upstream_busy_lock(p);
386 } else { 386 } else {
387 ngx_http_proxy_connect(p); 387 ngx_http_proxy_connect(p);
390 390
391 391
392 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p) 392 static void ngx_http_proxy_reinit_upstream(ngx_http_proxy_ctx_t *p)
393 { 393 {
394 ngx_chain_t *cl; 394 ngx_chain_t *cl;
395 ngx_output_chain_ctx_t *octx; 395 ngx_output_chain_ctx_t *output;
396 396
397 octx = 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 ngx_output_chain() context */
406 406
407 octx->hunk = NULL; 407 output->hunk = NULL;
408 octx->in = NULL; 408 output->in = NULL;
409 octx->free = NULL; 409 output->free = NULL;
410 octx->busy = NULL; 410 output->busy = NULL;
411 411
412 /* reinit r->header_in buffer */ 412 /* reinit r->header_in buffer */
413 413
414 if (p->header_in) { 414 if (p->header_in) {
415 if (p->cache) { 415 if (p->cache) {
485 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p) 485 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
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 *octx; 490 ngx_output_chain_ctx_t *output;
491 491
492 p->action = "connecting to upstream"; 492 p->action = "connecting to upstream";
493 493
494 rc = ngx_event_connect_peer(&p->upstream->peer); 494 rc = ngx_event_connect_peer(&p->upstream->peer);
495 495
515 r = p->request; 515 r = p->request;
516 c = p->upstream->peer.connection; 516 c = p->upstream->peer.connection;
517 c->pool = r->pool; 517 c->pool = r->pool;
518 c->read->log = c->write->log = c->log = r->connection->log; 518 c->read->log = c->write->log = c->log = r->connection->log;
519 519
520 octx = p->upstream->output_chain_ctx; 520 output = p->upstream->output_chain_ctx;
521 521
522 if (p->upstream->peer.tries > 1 && p->request_sent) { 522 if (p->upstream->peer.tries > 1 && p->request_sent) {
523 ngx_http_proxy_reinit_upstream(p); 523 ngx_http_proxy_reinit_upstream(p);
524 } 524 }
525 525
526 /* init or reinit ngx_output_chain() context */ 526 /* init or reinit ngx_output_chain() context */
527 527
528 if (r->request_body_hunk) { 528 if (r->request_body_hunk) {
529 if (!(octx->free = ngx_alloc_chain_link(r->pool))) { 529 if (!(output->free = ngx_alloc_chain_link(r->pool))) {
530 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 530 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
531 return; 531 return;
532 } 532 }
533 533
534 octx->free->hunk = r->request_body_hunk; 534 output->free->hunk = r->request_body_hunk;
535 octx->free->next = NULL; 535 output->free->next = NULL;
536 octx->hunks = 1; 536 output->hunks = 1;
537 537
538 r->request_body_hunk->pos = r->request_body_hunk->start; 538 r->request_body_hunk->pos = r->request_body_hunk->start;
539 r->request_body_hunk->last = r->request_body_hunk->start; 539 r->request_body_hunk->last = r->request_body_hunk->start;
540 } 540 }
541 541
563 563
564 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) 564 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p)
565 { 565 {
566 int rc; 566 int rc;
567 ngx_connection_t *c; 567 ngx_connection_t *c;
568 ngx_chain_writer_ctx_t *wctx; 568 ngx_chain_writer_ctx_t *writer;
569 569
570 c = p->upstream->peer.connection; 570 c = p->upstream->peer.connection;
571 571
572 #if (HAVE_KQUEUE) 572 #if (HAVE_KQUEUE)
573 573
584 584
585 #endif 585 #endif
586 586
587 p->action = "sending request to upstream"; 587 p->action = "sending request to upstream";
588 588
589 wctx = p->upstream->output_chain_ctx->output_ctx; 589 writer = p->upstream->output_chain_ctx->output_ctx;
590 wctx->out = NULL; 590 writer->out = NULL;
591 wctx->last = &wctx->out; 591 writer->last = &writer->out;
592 wctx->connection = c; 592 writer->connection = c;
593 593
594 rc = ngx_output_chain(p->upstream->output_chain_ctx, 594 rc = ngx_output_chain(p->upstream->output_chain_ctx,
595 p->request_sent ? NULL : p->request->request_hunks); 595 p->request_sent ? NULL : p->request->request_hunks);
596 596
597 if (rc == NGX_ERROR) { 597 if (rc == NGX_ERROR) {