}
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
}
/* 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");
}
}
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)
return (-1);
}
+ /* determine if it's a proxy request */
+ if (strlen(req->uri) > 0 && req->uri[0] != '/')
+ req->flags |= EVHTTP_PROXY_REQUEST;
+
return (0);
}
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);