Skip to content

Commit

Permalink
Client.new(): process impersonate first
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed May 13, 2024
1 parent c829a9b commit dfdaa83
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,17 @@ impl Client {
.enable_ech_grease()
.permute_extensions();

// Impersonate
if let Some(impersonation_type) = impersonate {
let impersonation = Impersonate::from_str(impersonation_type).map_err(|_| {
PyErr::new::<exceptions::PyValueError, _>("Invalid impersonate param")
})?;
client_builder = client_builder.impersonate(impersonation);
}

// Headers
if let Some(headers) = headers {
let mut headers_new = HeaderMap::new();
let mut headers_new = HeaderMap::with_capacity(headers.len());
for (key, value) in headers {
headers_new.insert(
HeaderName::from_bytes(key.as_bytes()).map_err(|_| {
Expand Down Expand Up @@ -171,14 +179,6 @@ impl Client {
client_builder = client_builder.timeout(Duration::from_secs_f64(seconds));
}

// Impersonate
if let Some(impersonation_type) = impersonate {
let impersonation = Impersonate::from_str(impersonation_type).map_err(|_| {
PyErr::new::<exceptions::PyValueError, _>("Invalid impersonate param")
})?;
client_builder = client_builder.impersonate(impersonation);
}

// Redirects
let max_redirects = max_redirects.unwrap_or(20); // Default to 20 if not provided
if follow_redirects.unwrap_or(true) {
Expand Down Expand Up @@ -298,7 +298,7 @@ impl Client {

// Headers
if let Some(headers) = headers {
let mut headers_new = HeaderMap::new();
let mut headers_new = HeaderMap::with_capacity(headers.len());
for (key, value) in headers {
headers_new.insert(
HeaderName::from_bytes(key.as_bytes()).map_err(|_| {
Expand Down

0 comments on commit dfdaa83

Please sign in to comment.