From: Daniel Stenberg Date: Tue, 8 Jun 2021 21:30:57 +0000 (+0200) Subject: c-hyper: abort CONNECT response reading early on non 2xx responses X-Git-Tag: curl-7_78_0~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c214a6a17b2b6f6e4720c40cec9a061b8504daf0;p=thirdparty%2Fcurl.git c-hyper: abort CONNECT response reading early on non 2xx responses Fixes test 493 Closes #7209 --- diff --git a/lib/c-hyper.c b/lib/c-hyper.c index c7102979ef..e3fd26c1ac 100644 --- a/lib/c-hyper.c +++ b/lib/c-hyper.c @@ -186,7 +186,13 @@ static int hyper_body_chunk(void *userdata, const hyper_buf *chunk) Curl_safefree(data->req.newurl); } #endif - result = Curl_http_firstwrite(data, data->conn, &done); + if(data->state.hconnect && + (data->req.httpcode/100 != 2)) { + done = TRUE; + result = CURLE_OK; + } + else + result = Curl_http_firstwrite(data, data->conn, &done); if(result || done) { infof(data, "Return early from hyper_body_chunk\n"); data->state.hresult = result; diff --git a/lib/http_proxy.c b/lib/http_proxy.c index cf408400e2..a67d9d3b41 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -744,6 +744,8 @@ static CURLcode CONNECT(struct Curl_easy *data, hyper_io_set_write(io, Curl_hyper_send); conn->sockfd = tunnelsocket; + data->state.hconnect = TRUE; + /* create an executor to poll futures */ if(!h->exec) { h->exec = hyper_executor_new(); diff --git a/lib/urldata.h b/lib/urldata.h index fb905c36c5..075f1848f0 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1411,6 +1411,7 @@ struct UrlState { trailers_state trailers_state; /* whether we are sending trailers and what stage are we at */ #ifdef USE_HYPER + bool hconnect; /* set if a CONNECT request */ CURLcode hresult; /* used to pass return codes back from hyper callbacks */ #endif diff --git a/tests/data/test493 b/tests/data/test493 index acce50b686..142b0c1c5d 100644 --- a/tests/data/test493 +++ b/tests/data/test493 @@ -1,6 +1,7 @@ +HTTP HSTS url_effective @@ -9,16 +10,16 @@ url_effective # we use this as response to a CONNECT - -HTTP/1.1 403 not OK at all -Date: Tue, 09 Nov 2010 14:49:00 GMT -Server: test-server/fake -Content-Length: 6 -Connection: close -Funny-head: yesyes - + +HTTP/1.1 403 not OK at all +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 6 +Connection: close +Funny-head: yesyes + -foo- - + @@ -53,6 +54,13 @@ Proxy-Connection: Keep-Alive +HTTP/1.1 403 not OK at all +Date: Tue, 09 Nov 2010 14:49:00 GMT +Server: test-server/fake +Content-Length: 6 +Connection: close +Funny-head: yesyes + https://this.hsts.example/%TESTNUMBER # Proxy CONNECT aborted