Skip to content

Commit c91d96a

Browse files
committed
fix(headers, cookies): set after impersonate
1 parent 7bc0fd1 commit c91d96a

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/lib.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,6 @@ impl RClient {
156156
client_builder = client_builder.impersonate(impersonate_builder);
157157
}
158158

159-
// Headers || Cookies
160-
if headers.is_some() || cookies.is_some() {
161-
let headers = headers.unwrap_or_else(|| IndexMap::with_hasher(RandomState::default()));
162-
let mut headers_headermap = headers.to_headermap();
163-
if let Some(cookies) = cookies {
164-
let cookies_str = cookies.to_string();
165-
headers_headermap.insert(COOKIE, HeaderValue::from_str(&cookies_str)?);
166-
}
167-
client_builder = client_builder.default_headers(headers_headermap);
168-
};
169-
170159
// Cookie_store
171160
if cookie_store.unwrap_or(true) {
172161
client_builder = client_builder.cookie_store(true);
@@ -220,10 +209,25 @@ impl RClient {
220209
client_builder = client_builder.http2_only();
221210
}
222211

223-
let client = Arc::new(Mutex::new(client_builder.build()?));
212+
let mut client = client_builder.build()?;
213+
214+
// Headers || Cookies
215+
if headers.is_some() || cookies.is_some() {
216+
let mut client_mut = client.as_mut();
217+
let client_headers = client_mut.headers();
218+
if let Some(headers) = headers {
219+
for (key, val) in headers {
220+
client_headers.insert_key_value(key, val)?;
221+
}
222+
}
223+
if let Some(cookies) = cookies {
224+
let cookies_str = cookies.to_string();
225+
client_headers.insert(COOKIE, HeaderValue::from_str(&cookies_str)?);
226+
}
227+
}
224228

225229
Ok(RClient {
226-
client,
230+
client: Arc::new(Mutex::new(client)),
227231
auth,
228232
auth_bearer,
229233
params,

0 commit comments

Comments
 (0)