mirror of
https://github.com/lwthiker/curl-impersonate.git
synced 2025-08-09 05:09:36 +00:00
Fix bug causing a wrong 'Host' header
When reusing a curl handle on which the 'Host' header was explicitly set, the previously-set header was being kept in use for following requests. The issue was in curl-impersonate's merging of user-supplied headers with its own list of browser headers. The call to Curl_http_merge_headers() which takes care of this had been placed after the handling of the host header, which caused the previous one to be used.
This commit is contained in:
@@ -760,7 +760,7 @@ index 04871ad1e..ce280eaa3 100644
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
diff --git a/lib/http.c b/lib/http.c
|
diff --git a/lib/http.c b/lib/http.c
|
||||||
index f08a343e3..879151dd2 100644
|
index f08a343e3..2bbce4b23 100644
|
||||||
--- a/lib/http.c
|
--- a/lib/http.c
|
||||||
+++ b/lib/http.c
|
+++ b/lib/http.c
|
||||||
@@ -84,6 +84,7 @@
|
@@ -84,6 +84,7 @@
|
||||||
@@ -908,16 +908,16 @@ index f08a343e3..879151dd2 100644
|
|||||||
CURLcode Curl_http_useragent(struct Curl_easy *data)
|
CURLcode Curl_http_useragent(struct Curl_easy *data)
|
||||||
{
|
{
|
||||||
/* The User-Agent string might have been allocated in url.c already, because
|
/* The User-Agent string might have been allocated in url.c already, because
|
||||||
@@ -3067,6 +3163,11 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
@@ -3063,6 +3159,11 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
||||||
if(result)
|
http = data->req.p.http;
|
||||||
return result;
|
DEBUGASSERT(http);
|
||||||
|
|
||||||
+ /* curl-impersonate: Add HTTP headers to impersonate real browsers. */
|
+ /* curl-impersonate: Add HTTP headers to impersonate real browsers. */
|
||||||
+ result = Curl_http_merge_headers(data);
|
+ result = Curl_http_merge_headers(data);
|
||||||
+ if (result)
|
+ if (result)
|
||||||
+ return result;
|
+ return result;
|
||||||
+
|
+
|
||||||
result = Curl_http_useragent(data);
|
result = Curl_http_host(data, conn);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
diff --git a/lib/http.h b/lib/http.h
|
diff --git a/lib/http.h b/lib/http.h
|
||||||
|
@@ -488,7 +488,7 @@ index 04871ad1e..cd5998146 100644
|
|||||||
{"HTTPPOST", CURLOPT_HTTPPOST, CURLOT_OBJECT, 0},
|
{"HTTPPOST", CURLOPT_HTTPPOST, CURLOT_OBJECT, 0},
|
||||||
{"HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL, CURLOT_LONG, 0},
|
{"HTTPPROXYTUNNEL", CURLOPT_HTTPPROXYTUNNEL, CURLOT_LONG, 0},
|
||||||
diff --git a/lib/http.c b/lib/http.c
|
diff --git a/lib/http.c b/lib/http.c
|
||||||
index f08a343e3..879151dd2 100644
|
index f08a343e3..2bbce4b23 100644
|
||||||
--- a/lib/http.c
|
--- a/lib/http.c
|
||||||
+++ b/lib/http.c
|
+++ b/lib/http.c
|
||||||
@@ -84,6 +84,7 @@
|
@@ -84,6 +84,7 @@
|
||||||
@@ -636,16 +636,16 @@ index f08a343e3..879151dd2 100644
|
|||||||
CURLcode Curl_http_useragent(struct Curl_easy *data)
|
CURLcode Curl_http_useragent(struct Curl_easy *data)
|
||||||
{
|
{
|
||||||
/* The User-Agent string might have been allocated in url.c already, because
|
/* The User-Agent string might have been allocated in url.c already, because
|
||||||
@@ -3067,6 +3163,11 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
@@ -3063,6 +3159,11 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
|
||||||
if(result)
|
http = data->req.p.http;
|
||||||
return result;
|
DEBUGASSERT(http);
|
||||||
|
|
||||||
+ /* curl-impersonate: Add HTTP headers to impersonate real browsers. */
|
+ /* curl-impersonate: Add HTTP headers to impersonate real browsers. */
|
||||||
+ result = Curl_http_merge_headers(data);
|
+ result = Curl_http_merge_headers(data);
|
||||||
+ if (result)
|
+ if (result)
|
||||||
+ return result;
|
+ return result;
|
||||||
+
|
+
|
||||||
result = Curl_http_useragent(data);
|
result = Curl_http_host(data, conn);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
diff --git a/lib/http2.c b/lib/http2.c
|
diff --git a/lib/http2.c b/lib/http2.c
|
||||||
|
Reference in New Issue
Block a user