mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-15 07:15:03 -04:00
try to make it work with proxy-connections
svn:r329
This commit is contained in:
parent
58f42c79e7
commit
fe2662384d
1
evhttp.h
1
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;
|
||||
|
30
http.c
30
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user