]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
c-hyper: abort CONNECT response reading early on non 2xx responses
authorDaniel Stenberg <daniel@haxx.se>
Tue, 8 Jun 2021 21:30:57 +0000 (23:30 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 10 Jun 2021 06:42:27 +0000 (08:42 +0200)
Fixes test 493

Closes #7209

lib/c-hyper.c
lib/http_proxy.c
lib/urldata.h
tests/data/test493

index c7102979efe12e2936bd8e071750268bd7f80ae7..e3fd26c1ace79aad2e64b7715bed2f1b1e56aca4 100644 (file)
@@ -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;
index cf408400e22d4957c78eca5e5e451729b90bea5e..a67d9d3b4115b782e86fdfcf4c22e412600c71e9 100644 (file)
@@ -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();
index fb905c36c573e47ba2b183d0246208499049daf9..075f1848f0df7a30d76b931f490e8dd7d5e8295f 100644 (file)
@@ -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
 
index acce50b686567605cfdcb737fea52f9ed898b335..142b0c1c5d06ffda310c72e67d47ac58af75ece9 100644 (file)
@@ -1,6 +1,7 @@
 <testcase>
 <info>
 <keywords>
+HTTP
 HSTS
 url_effective
 </keywords>
@@ -9,16 +10,16 @@ url_effective
 <reply>
 
 # we use this as response to a CONNECT
-<data nocheck="yes">
-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
-
+<connect nocheck="yes">
+HTTP/1.1 403 not OK at all\r
+Date: Tue, 09 Nov 2010 14:49:00 GMT\r
+Server: test-server/fake\r
+Content-Length: 6\r
+Connection: close\r
+Funny-head: yesyes\r
+\r
 -foo-
-</data>
+</connect>
 </reply>
 
 <client>
@@ -53,6 +54,13 @@ Proxy-Connection: Keep-Alive
 \r
 </protocol>
 <stdout>
+HTTP/1.1 403 not OK at all\r
+Date: Tue, 09 Nov 2010 14:49:00 GMT\r
+Server: test-server/fake\r
+Content-Length: 6\r
+Connection: close\r
+Funny-head: yesyes\r
+\r
 https://this.hsts.example/%TESTNUMBER
 </stdout>
 # Proxy CONNECT aborted