]> granicus.if.org Git - libevent/commitdiff
try to make it work with proxy-connections
authorNiels Provos <provos@gmail.com>
Thu, 15 Feb 2007 02:16:07 +0000 (02:16 +0000)
committerNiels Provos <provos@gmail.com>
Thu, 15 Feb 2007 02:16:07 +0000 (02:16 +0000)
svn:r329

evhttp.h
http.c

index 3f33c4874b4d20d23d74b6cdffd9ac3aeb0b67b0..162a796ab5fe8ad0457e0a0076566c730c83fe1c 100644 (file)
--- 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 aa66889bcf4030972e0cd7651933f0b78fb10879..31a19c9020861c2556603b5833dbc63cca6b540b 100644 (file)
--- 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);