comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 138:3b168e12bd2d

nginx-0.0.1-2003-10-06-07:56:42 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 06 Oct 2003 03:56:42 +0000
parents 2a615b036870
children 54307053f185
comparison
equal deleted inserted replaced
137:2a615b036870 138:3b168e12bd2d
14 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p); 14 static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p);
15 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev); 15 static void ngx_http_proxy_process_upstream_status_line(ngx_event_t *rev);
16 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); 16 static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev);
17 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); 17 static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *);
18 static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p); 18 static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p);
19 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p);
19 static void ngx_http_proxy_close_connection(ngx_connection_t *c); 20 static void ngx_http_proxy_close_connection(ngx_connection_t *c);
20 21
21 static int ngx_http_proxy_init(ngx_cycle_t *cycle); 22 static int ngx_http_proxy_init(ngx_cycle_t *cycle);
22 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); 23 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf);
23 24
384 p = c->data; 385 p = c->data;
385 386
386 ngx_log_debug(rev->log, "http proxy process status line"); 387 ngx_log_debug(rev->log, "http proxy process status line");
387 388
388 if (rev->timedout) { 389 if (rev->timedout) {
389 ngx_http_proxy_close_connection(c); 390 ngx_http_proxy_next_upstream(p);
390 ngx_http_finalize_request(p->request, NGX_HTTP_GATEWAY_TIME_OUT);
391 return; 391 return;
392 } 392 }
393 393
394 if (p->header_in == NULL) { 394 if (p->header_in == NULL) {
395 p->header_in = ngx_create_temp_hunk(p->request->pool, 395 p->header_in = ngx_create_temp_hunk(p->request->pool,
403 } 403 }
404 } 404 }
405 405
406 n = ngx_http_proxy_read_upstream_header(p); 406 n = ngx_http_proxy_read_upstream_header(p);
407 407
408 if (n == NGX_AGAIN || n == NGX_ERROR) { 408 if (n == NGX_ERROR) {
409 ngx_http_proxy_next_upstream(p);
410 return;
411 }
412
413 if (n == NGX_AGAIN) {
409 return; 414 return;
410 } 415 }
411 416
412 rc = ngx_http_proxy_parse_status_line(p); 417 rc = ngx_http_proxy_parse_status_line(p);
413 418
471 r = p->request; 476 r = p->request;
472 477
473 ngx_log_debug(rev->log, "http proxy process header line"); 478 ngx_log_debug(rev->log, "http proxy process header line");
474 479
475 if (rev->timedout) { 480 if (rev->timedout) {
476 ngx_http_proxy_close_connection(c); 481 ngx_http_proxy_next_upstream(p);
477 ngx_http_finalize_request(p->request, NGX_HTTP_GATEWAY_TIME_OUT);
478 return; 482 return;
479 } 483 }
480 484
481 rc = NGX_AGAIN; 485 rc = NGX_AGAIN;
482 486
483 for ( ;; ) { 487 for ( ;; ) {
484 if (rc == NGX_AGAIN) { 488 if (rc == NGX_AGAIN) {
485 n = ngx_http_proxy_read_upstream_header(p); 489 n = ngx_http_proxy_read_upstream_header(p);
486 490
487 if (n == NGX_AGAIN || n == NGX_ERROR) { 491 if (n == NGX_ERROR) {
492 ngx_http_proxy_next_upstream(p);
493 return;
494 }
495
496 if (n == NGX_AGAIN) {
488 return; 497 return;
489 } 498 }
490 } 499 }
491 500
492 rc = ngx_http_parse_header_line(p->request, p->header_in); 501 rc = ngx_http_parse_header_line(p->request, p->header_in);
547 556
548 /* there was error while a header line parsing */ 557 /* there was error while a header line parsing */
549 558
550 #if 0 559 #if 0
551 ngx_http_header_parse_error(r, rc); 560 ngx_http_header_parse_error(r, rc);
561 ngx_http_proxy_next_upstream(p);
552 #endif 562 #endif
553 ngx_http_proxy_close_connection(c); 563 ngx_http_proxy_close_connection(c);
554 ngx_http_finalize_request(p->request, NGX_HTTP_BAD_GATEWAY); 564 ngx_http_finalize_request(p->request, NGX_HTTP_BAD_GATEWAY);
555 return; 565 return;
556 } 566 }
620 ngx_log_error(NGX_LOG_INFO, rev->log, 0, 630 ngx_log_error(NGX_LOG_INFO, rev->log, 0,
621 "upstream closed prematurely connection"); 631 "upstream closed prematurely connection");
622 } 632 }
623 633
624 if (n == 0 || n == NGX_ERROR) { 634 if (n == 0 || n == NGX_ERROR) {
625 ngx_http_proxy_close_connection(p->upstream.connection);
626 ngx_http_finalize_request(p->request, NGX_HTTP_BAD_GATEWAY);
627 return NGX_ERROR; 635 return NGX_ERROR;
628 } 636 }
629 637
630 p->header_in->last += n; 638 p->header_in->last += n;
631 639
829 837
830 p->state = state; 838 p->state = state;
831 return NGX_AGAIN; 839 return NGX_AGAIN;
832 } 840 }
833 841
842 static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p)
843 {
844 if (p->upstream.connection) {
845 ngx_http_proxy_close_connection(p->upstream.connection);
846 p->upstream.connection = NULL;
847
848 ngx_http_proxy_send_request(p);
849 }
850
851 return;
852 }
853
834 854
835 static void ngx_http_proxy_close_connection(ngx_connection_t *c) 855 static void ngx_http_proxy_close_connection(ngx_connection_t *c)
836 { 856 {
837 ngx_log_debug(c->log, "close connection: %d" _ c->fd); 857 ngx_log_debug(c->log, "close connection: %d" _ c->fd);
838 858