]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
c-hyper: use hyper_request_set_uri_parts to make h2 better
authorDaniel Stenberg <daniel@haxx.se>
Fri, 8 Oct 2021 09:33:50 +0000 (11:33 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 8 Oct 2021 13:14:29 +0000 (15:14 +0200)
and make sure to not send Host: over h2.

Fixes #7679
Reported-by: David Cook
Closes #7827

lib/c-hyper.c

index 26635cdc1e10ccf8a6b9fd2f2df2a58b6ad71f83..81e86c2adb635e8156941e96cbb27a465d90d97a 100644 (file)
@@ -584,9 +584,22 @@ static CURLcode request_target(struct Curl_easy *data,
   if(result)
     return result;
 
-  if(hyper_request_set_uri(req, (uint8_t *)Curl_dyn_uptr(&r),
-                           Curl_dyn_len(&r))) {
-    failf(data, "error setting path");
+  if(h2 && hyper_request_set_uri_parts(req,
+                                       /* scheme */
+                                       (uint8_t *)data->state.up.scheme,
+                                       strlen(data->state.up.scheme),
+                                       /* authority */
+                                       (uint8_t *)conn->host.name,
+                                       strlen(conn->host.name),
+                                       /* path_and_query */
+                                       (uint8_t *)Curl_dyn_uptr(&r),
+                                       Curl_dyn_len(&r))) {
+    failf(data, "error setting uri parts to hyper");
+    result = CURLE_OUT_OF_MEMORY;
+  }
+  else if(!h2 && hyper_request_set_uri(req, (uint8_t *)Curl_dyn_uptr(&r),
+                                       Curl_dyn_len(&r))) {
+    failf(data, "error setting uri to hyper");
     result = CURLE_OUT_OF_MEMORY;
   }
   else
@@ -939,9 +952,21 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
   if(result)
     return result;
 
-  if(data->state.aptr.host &&
-     Curl_hyper_header(data, headers, data->state.aptr.host))
-    goto error;
+  if(!h2) {
+    if(data->state.aptr.host &&
+       Curl_hyper_header(data, headers, data->state.aptr.host))
+      goto error;
+  }
+  else {
+    /* For HTTP/2, we show the Host: header as if we sent it, to make it look
+       like for HTTP/1 but it isn't actually sent since :authority is then
+       used. */
+    if(Curl_debug(data, CURLINFO_HEADER_OUT, data->state.aptr.host,
+                  strlen(data->state.aptr.host))) {
+      result = CURLE_ABORTED_BY_CALLBACK;
+      goto error;
+    }
+  }
 
   if(data->state.aptr.proxyuserpwd &&
      Curl_hyper_header(data, headers, data->state.aptr.proxyuserpwd))