diff options
author | Azat Khuzhin <azat@libevent.org> | 2020-01-12 15:24:35 +0300 |
---|---|---|
committer | Azat Khuzhin <azat@libevent.org> | 2020-01-12 15:34:01 +0300 |
commit | 415ddee3379def05c93be740ada59204fbadb0af (patch) | |
tree | b7ca079c050a0062bfffbcdfdcdb5b4868c9edfa /sample | |
parent | e54d5fc57ce23cbbe988fe242aee25c50049978b (diff) | |
download | libevent-415ddee3379def05c93be740ada59204fbadb0af.tar.gz |
http-connect: set Host header (for CONNECT and GET) (like curl)
Diffstat (limited to 'sample')
-rw-r--r-- | sample/http-connect.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sample/http-connect.c b/sample/http-connect.c index 16376ddc..b08bb25d 100644 --- a/sample/http-connect.c +++ b/sample/http-connect.c @@ -84,13 +84,14 @@ static void connect_cb(struct evhttp_request *proxy_req, void *arg) req = evhttp_request_new(get_cb, NULL); evhttp_add_header(req->output_headers, "Connection", "close"); + evhttp_add_header(req->output_headers, "Host", evhttp_uri_get_host(location)); VERIFY(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET, uri_path(location, buffer))); } int main(int argc, const char **argv) { - char buffer[URL_MAX]; + char hostport[URL_MAX]; struct evhttp_uri *location; struct evhttp_uri *proxy; @@ -116,10 +117,11 @@ int main(int argc, const char **argv) connect_base.location = location; VERIFY(req = evhttp_request_new(connect_cb, &connect_base)); + uri_hostport(location, hostport); evhttp_add_header(req->output_headers, "Connection", "keep-alive"); evhttp_add_header(req->output_headers, "Proxy-Connection", "keep-alive"); - evhttp_make_request(evcon, req, EVHTTP_REQ_CONNECT, - uri_hostport(location, buffer)); + evhttp_add_header(req->output_headers, "Host", hostport); + evhttp_make_request(evcon, req, EVHTTP_REQ_CONNECT, hostport); event_base_dispatch(base); |