# HG changeset patch # User Igor Sysoev # Date 1065412602 0 # Node ID 3b168e12bd2d244278ad1de1a76d3ea36c3c4553 # Parent 2a615b036870ff865ef08aab2c67ac24b9614b7d nginx-0.0.1-2003-10-06-07:56:42 import diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -16,6 +16,7 @@ static void ngx_http_proxy_process_upstr static void ngx_http_proxy_process_upstream_headers(ngx_event_t *rev); static ssize_t ngx_http_proxy_read_upstream_header(ngx_http_proxy_ctx_t *); static int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p); +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p); static void ngx_http_proxy_close_connection(ngx_connection_t *c); static int ngx_http_proxy_init(ngx_cycle_t *cycle); @@ -386,8 +387,7 @@ static void ngx_http_proxy_process_upstr ngx_log_debug(rev->log, "http proxy process status line"); if (rev->timedout) { - ngx_http_proxy_close_connection(c); - ngx_http_finalize_request(p->request, NGX_HTTP_GATEWAY_TIME_OUT); + ngx_http_proxy_next_upstream(p); return; } @@ -405,7 +405,12 @@ static void ngx_http_proxy_process_upstr n = ngx_http_proxy_read_upstream_header(p); - if (n == NGX_AGAIN || n == NGX_ERROR) { + if (n == NGX_ERROR) { + ngx_http_proxy_next_upstream(p); + return; + } + + if (n == NGX_AGAIN) { return; } @@ -473,8 +478,7 @@ static void ngx_http_proxy_process_upstr ngx_log_debug(rev->log, "http proxy process header line"); if (rev->timedout) { - ngx_http_proxy_close_connection(c); - ngx_http_finalize_request(p->request, NGX_HTTP_GATEWAY_TIME_OUT); + ngx_http_proxy_next_upstream(p); return; } @@ -484,7 +488,12 @@ static void ngx_http_proxy_process_upstr if (rc == NGX_AGAIN) { n = ngx_http_proxy_read_upstream_header(p); - if (n == NGX_AGAIN || n == NGX_ERROR) { + if (n == NGX_ERROR) { + ngx_http_proxy_next_upstream(p); + return; + } + + if (n == NGX_AGAIN) { return; } } @@ -549,6 +558,7 @@ static void ngx_http_proxy_process_upstr #if 0 ngx_http_header_parse_error(r, rc); + ngx_http_proxy_next_upstream(p); #endif ngx_http_proxy_close_connection(c); ngx_http_finalize_request(p->request, NGX_HTTP_BAD_GATEWAY); @@ -622,8 +632,6 @@ static ssize_t ngx_http_proxy_read_upstr } if (n == 0 || n == NGX_ERROR) { - ngx_http_proxy_close_connection(p->upstream.connection); - ngx_http_finalize_request(p->request, NGX_HTTP_BAD_GATEWAY); return NGX_ERROR; } @@ -831,6 +839,18 @@ static int ngx_http_proxy_parse_status_l return NGX_AGAIN; } +static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p) +{ + if (p->upstream.connection) { + ngx_http_proxy_close_connection(p->upstream.connection); + p->upstream.connection = NULL; + + ngx_http_proxy_send_request(p); + } + + return; +} + static void ngx_http_proxy_close_connection(ngx_connection_t *c) { diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -52,6 +52,7 @@ struct ngx_http_proxy_ctx_s { int location_len; ngx_str_t host_header; + /* used to parse an upstream HTTP header */ char *status_start; char *status_end; int status_count; @@ -61,7 +62,7 @@ struct ngx_http_proxy_ctx_s { }; -#define NGX_HTTP_PROXY_PARSE_NO_HEADER 10 +#define NGX_HTTP_PROXY_PARSE_NO_HEADER 20 #endif /* _NGX_HTTP_PROXY_HANDLER_H_INCLUDED_ */