Mercurial > hg > nginx-vendor-1-0
diff 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 |
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -90,6 +90,8 @@ static void *ngx_http_upstream_create_ma static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); #if (NGX_HTTP_SSL) +static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *, + ngx_http_upstream_t *u, ngx_connection_t *c); static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c); static void ngx_http_upstream_ssl_shutdown(ngx_connection_t *c, ngx_peer_t *peer); @@ -498,9 +500,8 @@ ngx_http_upstream_check_broken_connectio static void ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u) { - ngx_int_t rc; - ngx_peer_t *peer; - ngx_connection_t *c; + ngx_int_t rc; + ngx_connection_t *c; r->connection->log->action = "connecting to upstream"; @@ -517,8 +518,7 @@ ngx_http_upstream_connect(ngx_http_reque return; } - peer = &u->peer.peers->peer[u->peer.cur_peer]; - u->state->peer = &peer->name; + u->state->peer = &u->peer.peers->peer[u->peer.cur_peer].name; if (rc == NGX_BUSY) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams"); @@ -534,6 +534,7 @@ ngx_http_upstream_connect(ngx_http_reque c = u->peer.connection; c->data = r; + c->write->handler = ngx_http_upstream_send_request_handler; c->read->handler = ngx_http_upstream_process_header; @@ -587,40 +588,10 @@ ngx_http_upstream_connect(ngx_http_reque return; } - /* rc == NGX_OK */ - #if (NGX_HTTP_SSL) - if (u->conf->ssl) { - if (c->ssl == NULL) { - - if (ngx_ssl_create_connection(u->conf->ssl, c, - NGX_SSL_BUFFER|NGX_SSL_CLIENT) - == NGX_ERROR) - { - ngx_http_upstream_finalize_request(r, u, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - c->sendfile = 0; - } - - if (ngx_ssl_set_session(c, peer->ssl_session) != NGX_OK) { - ngx_http_upstream_finalize_request(r, u, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - rc = ngx_ssl_handshake(c); - - if (rc == NGX_AGAIN) { - c->ssl->handler = ngx_http_upstream_ssl_handshake; - return; - } - - ngx_http_upstream_ssl_handshake(c); - + if (u->conf->ssl && c->ssl == NULL) { + ngx_http_upstream_ssl_init_connection(r, u, c); return; } @@ -633,6 +604,43 @@ ngx_http_upstream_connect(ngx_http_reque #if (NGX_HTTP_SSL) static void +ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r, + ngx_http_upstream_t *u, ngx_connection_t *c) +{ + ngx_int_t rc; + ngx_peer_t *peer; + + if (ngx_ssl_create_connection(u->conf->ssl, c, + NGX_SSL_BUFFER|NGX_SSL_CLIENT) + == NGX_ERROR) + { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } + + c->sendfile = 0; + + peer = &u->peer.peers->peer[u->peer.cur_peer]; + + if (ngx_ssl_set_session(c, peer->ssl_session) != NGX_OK) { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } + + rc = ngx_ssl_handshake(c); + + if (rc == NGX_AGAIN) { + c->ssl->handler = ngx_http_upstream_ssl_handshake; + return; + } + + ngx_http_upstream_ssl_handshake(c); +} + + +static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c) { ngx_http_request_t *r; @@ -671,7 +679,8 @@ ngx_http_upstream_reinit(ngx_http_reques sizeof(ngx_http_upstream_headers_in_t)); if (ngx_list_init(&r->upstream->headers_in.headers, r->pool, 8, - sizeof(ngx_table_elt_t)) != NGX_OK) + sizeof(ngx_table_elt_t)) + != NGX_OK) { return NGX_ERROR; } @@ -851,6 +860,15 @@ ngx_http_upstream_send_request_handler(n return; } +#if (NGX_HTTP_SSL) + + if (u->conf->ssl && c->ssl == NULL) { + ngx_http_upstream_ssl_init_connection(r, u, c); + return; + } + +#endif + ngx_http_upstream_send_request(r, u); }