try to make it work with proxy-connections

svn:r329
This commit is contained in:
Niels Provos 2007-02-15 02:16:07 +00:00
parent 58f42c79e7
commit fe2662384d
2 changed files with 22 additions and 9 deletions

View File

@ -109,6 +109,7 @@ struct evhttp_request {
struct evhttp_connection *evcon; struct evhttp_connection *evcon;
int flags; int flags;
#define EVHTTP_REQ_OWN_CONNECTION 0x0001 #define EVHTTP_REQ_OWN_CONNECTION 0x0001
#define EVHTTP_PROXY_REQUEST 0x0002
struct evkeyvalq *input_headers; struct evkeyvalq *input_headers;
struct evkeyvalq *output_headers; struct evkeyvalq *output_headers;

30
http.c
View File

@ -310,10 +310,16 @@ evhttp_make_header_request(struct evhttp_connection *evcon,
} }
static int 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"); if (flags & EVHTTP_PROXY_REQUEST) {
return (connection != NULL && strcasecmp(connection, "close") == 0); /* 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 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 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_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; req->evcon = NULL;
need_close = need_close =
evhttp_is_connection_close(req->input_headers) || evhttp_is_connection_close(req->flags, req->input_headers) ||
evhttp_is_connection_close(req->output_headers); evhttp_is_connection_close(req->flags, req->output_headers);
/* check if we got asked to close the connection */ /* check if we got asked to close the connection */
if (need_close) if (need_close)
@ -1043,6 +1051,10 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
return (-1); return (-1);
} }
/* determine if it's a proxy request */
if (strlen(req->uri) > 0 && req->uri[0] != '/')
req->flags |= EVHTTP_PROXY_REQUEST;
return (0); return (0);
} }
@ -1511,8 +1523,8 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg)
need_close = need_close =
(req->minor == 0 && (req->minor == 0 &&
!evhttp_is_connection_keepalive(req->input_headers))|| !evhttp_is_connection_keepalive(req->input_headers))||
evhttp_is_connection_close(req->input_headers) || evhttp_is_connection_close(req->flags, req->input_headers) ||
evhttp_is_connection_close(req->output_headers); evhttp_is_connection_close(req->flags, req->output_headers);
assert(req->flags & EVHTTP_REQ_OWN_CONNECTION); assert(req->flags & EVHTTP_REQ_OWN_CONNECTION);
evhttp_request_free(req); evhttp_request_free(req);