From: Greg Hazel Date: Sat, 2 Dec 2017 20:53:57 +0000 (-0800) Subject: CONNECT method only takes an authority X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65eb529a9f4dd886d01a9d77ce6d971de9fb1b97;p=libevent CONNECT method only takes an authority --- diff --git a/http.c b/http.c index 4a77fbb8..b3087b5b 100644 --- a/http.c +++ b/http.c @@ -173,6 +173,7 @@ extern int debug; static evutil_socket_t bind_socket_ai(struct evutil_addrinfo *, int reuse); static evutil_socket_t bind_socket(const char *, ev_uint16_t, int reuse); static void name_from_addr(struct sockaddr *, ev_socklen_t, char **, char **); +static struct evhttp_uri *evhttp_uri_parse_authority(char *source_uri); static int evhttp_associate_new_request_with_connection( struct evhttp_connection *evcon); static void evhttp_connection_start_detectclose( @@ -1831,9 +1832,15 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line) return (-1); } - if ((req->uri_elems = evhttp_uri_parse_with_flags(req->uri, - EVHTTP_URI_NONCONFORMANT)) == NULL) { - return -1; + if (type == EVHTTP_REQ_CONNECT) { + if ((req->uri_elems = evhttp_uri_parse_authority(req->uri)) == NULL) { + return -1; + } + } else { + if ((req->uri_elems = evhttp_uri_parse_with_flags(req->uri, + EVHTTP_URI_NONCONFORMANT)) == NULL) { + return -1; + } } /* If we have an absolute-URI, check to see if it is an http request @@ -4828,6 +4835,34 @@ err: return NULL; } +static struct evhttp_uri * +evhttp_uri_parse_authority(char *source_uri) +{ + struct evhttp_uri *uri = mm_calloc(1, sizeof(struct evhttp_uri)); + if (uri == NULL) { + event_warn("%s: calloc", __func__); + goto err; + } + uri->port = -1; + uri->flags = 0; + + char *end = end_of_authority(source_uri); + if (parse_authority(uri, source_uri, end) < 0) + goto err; + + uri->path = mm_strdup(""); + if (uri->path == NULL) { + event_warn("%s: strdup", __func__); + goto err; + } + + return uri; +err: + if (uri) + evhttp_uri_free(uri); + return NULL; +} + void evhttp_uri_free(struct evhttp_uri *uri) {