From: Niels Provos Date: Thu, 15 Feb 2007 02:16:07 +0000 (+0000) Subject: try to make it work with proxy-connections X-Git-Tag: release-2.0.1-alpha~646 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe2662384db52b1e4c500bbb9939a97545178c46;p=libevent try to make it work with proxy-connections svn:r329 --- diff --git a/evhttp.h b/evhttp.h index 3f33c487..162a796a 100644 --- a/evhttp.h +++ b/evhttp.h @@ -109,6 +109,7 @@ struct evhttp_request { struct evhttp_connection *evcon; int flags; #define EVHTTP_REQ_OWN_CONNECTION 0x0001 +#define EVHTTP_PROXY_REQUEST 0x0002 struct evkeyvalq *input_headers; struct evkeyvalq *output_headers; diff --git a/http.c b/http.c index aa66889b..31a19c90 100644 --- a/http.c +++ b/http.c @@ -310,10 +310,16 @@ evhttp_make_header_request(struct evhttp_connection *evcon, } static int -evhttp_is_connection_close(struct evkeyvalq* headers) +evhttp_is_connection_close(int flags, struct evkeyvalq* headers) { - const char *connection = evhttp_find_header(headers, "Connection"); - return (connection != NULL && strcasecmp(connection, "close") == 0); + if (flags & EVHTTP_PROXY_REQUEST) { + /* proxy connection */ + const char *connection = evhttp_find_header(headers, "Proxy-Connection"); + return (connection == NULL || strcasecmp(connection, "keep-alive") != 0); + } else { + const char *connection = evhttp_find_header(headers, "Connection"); + return (connection != NULL && strcasecmp(connection, "close") == 0); + } } static int @@ -363,9 +369,11 @@ evhttp_make_header_response(struct evhttp_connection *evcon, } /* if the request asked for a close, we send a close, too */ - if (evhttp_is_connection_close(req->input_headers)) { + if (evhttp_is_connection_close(req->flags, req->input_headers)) { evhttp_remove_header(req->output_headers, "Connection"); - evhttp_add_header(req->output_headers, "Connection", "close"); + if (!(req->flags & EVHTTP_PROXY_REQUEST)) + evhttp_add_header(req->output_headers, "Connection", "close"); + evhttp_remove_header(req->output_headers, "Proxy-Connection"); } } @@ -576,8 +584,8 @@ evhttp_connection_done(struct evhttp_connection *evcon) req->evcon = NULL; need_close = - evhttp_is_connection_close(req->input_headers) || - evhttp_is_connection_close(req->output_headers); + evhttp_is_connection_close(req->flags, req->input_headers) || + evhttp_is_connection_close(req->flags, req->output_headers); /* check if we got asked to close the connection */ if (need_close) @@ -1043,6 +1051,10 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line) return (-1); } + /* determine if it's a proxy request */ + if (strlen(req->uri) > 0 && req->uri[0] != '/') + req->flags |= EVHTTP_PROXY_REQUEST; + return (0); } @@ -1511,8 +1523,8 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg) need_close = (req->minor == 0 && !evhttp_is_connection_keepalive(req->input_headers))|| - evhttp_is_connection_close(req->input_headers) || - evhttp_is_connection_close(req->output_headers); + evhttp_is_connection_close(req->flags, req->input_headers) || + evhttp_is_connection_close(req->flags, req->output_headers); assert(req->flags & EVHTTP_REQ_OWN_CONNECTION); evhttp_request_free(req);