comparison src/http/ngx_http_upstream.c @ 140:55a211e5eeb7 NGINX_0_3_17

nginx 0.3.17 *) Change: now on Linux configure checks the presence of epoll and sendfile64() in kernel. *) Feature: the "map" directive supports domain names in the ".domain.tld" form. *) Bugfix: the timeouts were not used in SSL handshake; bug appeared in 0.2.4. *) Bugfix: in the HTTPS protocol in the "proxy_pass" directive. *) Bugfix: when the HTTPS protocol was used in the "proxy_pass" directive the port 80 was used by default.
author Igor Sysoev <http://sysoev.ru>
date Sun, 18 Dec 2005 00:00:00 +0300
parents 8e6d4d96ec4c
children 84910468f6de
comparison
equal deleted inserted replaced
139:9cee8bc94578 140:55a211e5eeb7
88 88
89 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf); 89 static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
90 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); 90 static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
91 91
92 #if (NGX_HTTP_SSL) 92 #if (NGX_HTTP_SSL)
93 static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *,
94 ngx_http_upstream_t *u, ngx_connection_t *c);
93 static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c); 95 static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c);
94 static void ngx_http_upstream_ssl_shutdown(ngx_connection_t *c, 96 static void ngx_http_upstream_ssl_shutdown(ngx_connection_t *c,
95 ngx_peer_t *peer); 97 ngx_peer_t *peer);
96 #endif 98 #endif
97 99
496 498
497 499
498 static void 500 static void
499 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) 501 ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
500 { 502 {
501 ngx_int_t rc; 503 ngx_int_t rc;
502 ngx_peer_t *peer; 504 ngx_connection_t *c;
503 ngx_connection_t *c;
504 505
505 r->connection->log->action = "connecting to upstream"; 506 r->connection->log->action = "connecting to upstream";
506 507
507 r->connection->single_connection = 0; 508 r->connection->single_connection = 0;
508 509
515 ngx_http_upstream_finalize_request(r, u, 516 ngx_http_upstream_finalize_request(r, u,
516 NGX_HTTP_INTERNAL_SERVER_ERROR); 517 NGX_HTTP_INTERNAL_SERVER_ERROR);
517 return; 518 return;
518 } 519 }
519 520
520 peer = &u->peer.peers->peer[u->peer.cur_peer]; 521 u->state->peer = &u->peer.peers->peer[u->peer.cur_peer].name;
521 u->state->peer = &peer->name;
522 522
523 if (rc == NGX_BUSY) { 523 if (rc == NGX_BUSY) {
524 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); 524 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");
525 } 525 }
526 526
532 /* rc == NGX_OK || rc == NGX_AGAIN */ 532 /* rc == NGX_OK || rc == NGX_AGAIN */
533 533
534 c = u->peer.connection; 534 c = u->peer.connection;
535 535
536 c->data = r; 536 c->data = r;
537
537 c->write->handler = ngx_http_upstream_send_request_handler; 538 c->write->handler = ngx_http_upstream_send_request_handler;
538 c->read->handler = ngx_http_upstream_process_header; 539 c->read->handler = ngx_http_upstream_process_header;
539 540
540 c->sendfile = r->connection->sendfile; 541 c->sendfile = r->connection->sendfile;
541 542
585 if (rc == NGX_AGAIN) { 586 if (rc == NGX_AGAIN) {
586 ngx_add_timer(c->write, u->conf->connect_timeout); 587 ngx_add_timer(c->write, u->conf->connect_timeout);
587 return; 588 return;
588 } 589 }
589 590
590 /* rc == NGX_OK */
591
592 #if (NGX_HTTP_SSL) 591 #if (NGX_HTTP_SSL)
593 592
594 if (u->conf->ssl) { 593 if (u->conf->ssl && c->ssl == NULL) {
595 if (c->ssl == NULL) { 594 ngx_http_upstream_ssl_init_connection(r, u, c);
596
597 if (ngx_ssl_create_connection(u->conf->ssl, c,
598 NGX_SSL_BUFFER|NGX_SSL_CLIENT)
599 == NGX_ERROR)
600 {
601 ngx_http_upstream_finalize_request(r, u,
602 NGX_HTTP_INTERNAL_SERVER_ERROR);
603 return;
604 }
605
606 c->sendfile = 0;
607 }
608
609 if (ngx_ssl_set_session(c, peer->ssl_session) != NGX_OK) {
610 ngx_http_upstream_finalize_request(r, u,
611 NGX_HTTP_INTERNAL_SERVER_ERROR);
612 return;
613 }
614
615 rc = ngx_ssl_handshake(c);
616
617 if (rc == NGX_AGAIN) {
618 c->ssl->handler = ngx_http_upstream_ssl_handshake;
619 return;
620 }
621
622 ngx_http_upstream_ssl_handshake(c);
623
624 return; 595 return;
625 } 596 }
626 597
627 #endif 598 #endif
628 599
629 ngx_http_upstream_send_request(r, u); 600 ngx_http_upstream_send_request(r, u);
630 } 601 }
631 602
632 603
633 #if (NGX_HTTP_SSL) 604 #if (NGX_HTTP_SSL)
605
606 static void
607 ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
608 ngx_http_upstream_t *u, ngx_connection_t *c)
609 {
610 ngx_int_t rc;
611 ngx_peer_t *peer;
612
613 if (ngx_ssl_create_connection(u->conf->ssl, c,
614 NGX_SSL_BUFFER|NGX_SSL_CLIENT)
615 == NGX_ERROR)
616 {
617 ngx_http_upstream_finalize_request(r, u,
618 NGX_HTTP_INTERNAL_SERVER_ERROR);
619 return;
620 }
621
622 c->sendfile = 0;
623
624 peer = &u->peer.peers->peer[u->peer.cur_peer];
625
626 if (ngx_ssl_set_session(c, peer->ssl_session) != NGX_OK) {
627 ngx_http_upstream_finalize_request(r, u,
628 NGX_HTTP_INTERNAL_SERVER_ERROR);
629 return;
630 }
631
632 rc = ngx_ssl_handshake(c);
633
634 if (rc == NGX_AGAIN) {
635 c->ssl->handler = ngx_http_upstream_ssl_handshake;
636 return;
637 }
638
639 ngx_http_upstream_ssl_handshake(c);
640 }
641
634 642
635 static void 643 static void
636 ngx_http_upstream_ssl_handshake(ngx_connection_t *c) 644 ngx_http_upstream_ssl_handshake(ngx_connection_t *c)
637 { 645 {
638 ngx_http_request_t *r; 646 ngx_http_request_t *r;
669 677
670 ngx_memzero(&r->upstream->headers_in, 678 ngx_memzero(&r->upstream->headers_in,
671 sizeof(ngx_http_upstream_headers_in_t)); 679 sizeof(ngx_http_upstream_headers_in_t));
672 680
673 if (ngx_list_init(&r->upstream->headers_in.headers, r->pool, 8, 681 if (ngx_list_init(&r->upstream->headers_in.headers, r->pool, 8,
674 sizeof(ngx_table_elt_t)) != NGX_OK) 682 sizeof(ngx_table_elt_t))
683 != NGX_OK)
675 { 684 {
676 return NGX_ERROR; 685 return NGX_ERROR;
677 } 686 }
678 687
679 /* reinit the request chain */ 688 /* reinit the request chain */
848 if (wev->timedout) { 857 if (wev->timedout) {
849 c->log->action = "sending request to upstream"; 858 c->log->action = "sending request to upstream";
850 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT); 859 ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
851 return; 860 return;
852 } 861 }
862
863 #if (NGX_HTTP_SSL)
864
865 if (u->conf->ssl && c->ssl == NULL) {
866 ngx_http_upstream_ssl_init_connection(r, u, c);
867 return;
868 }
869
870 #endif
853 871
854 ngx_http_upstream_send_request(r, u); 872 ngx_http_upstream_send_request(r, u);
855 } 873 }
856 874
857 875