]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
pretransfer: setup the User-Agent header here
authorDaniel Stenberg <daniel@haxx.se>
Tue, 5 Jan 2021 13:30:21 +0000 (14:30 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 5 Jan 2021 22:46:32 +0000 (23:46 +0100)
... and not in the connection setup, as for multiplexed transfers the
connection setup might be skipped and then the transfer would end up
without the set user-agent!

Reported-by: Flameborn on github
Assisted-by: Andrey Gursky
Assisted-by: Jay Satiro
Assisted-by: Mike Gelfand
Fixes #6312
Closes #6417

lib/transfer.c
lib/url.c

index 7b5a0516defb8a729a88ac4f17f18bf4cf9fa576..baf305fe123d2b8d74c2625b5a7662f42d0ba661 100644 (file)
@@ -1495,6 +1495,20 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
     Curl_hsts_loadcb(data, data->hsts);
   }
 
+  /*
+   * Set user-agent. Used for HTTP, but since we can attempt to tunnel
+   * basically anything through a http proxy we can't limit this based on
+   * protocol.
+   */
+  if(data->set.str[STRING_USERAGENT]) {
+    Curl_safefree(data->state.aptr.uagent);
+    data->state.aptr.uagent =
+      aprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]);
+    if(!data->state.aptr.uagent)
+      return CURLE_OUT_OF_MEMORY;
+  }
+
+  data->req.headerbytecount = 0;
   return result;
 }
 
index 45577713e96088433cff41df7f171fa6631127af..60ba56dae63c41cf1db1e5422f378fd609452088 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3942,20 +3942,6 @@ CURLcode Curl_setup_conn(struct connectdata *conn,
      lingering set from a previous invoke */
   conn->bits.proxy_connect_closed = FALSE;
 #endif
-  /*
-   * Set user-agent. Used for HTTP, but since we can attempt to tunnel
-   * basically anything through a http proxy we can't limit this based on
-   * protocol.
-   */
-  if(data->set.str[STRING_USERAGENT]) {
-    Curl_safefree(data->state.aptr.uagent);
-    data->state.aptr.uagent =
-      aprintf("User-Agent: %s\r\n", data->set.str[STRING_USERAGENT]);
-    if(!data->state.aptr.uagent)
-      return CURLE_OUT_OF_MEMORY;
-  }
-
-  data->req.headerbytecount = 0;
 
 #ifdef CURL_DO_LINEEND_CONV
   data->state.crlf_conversions = 0; /* reset CRLF conversion counter */