diff --git a/src/lib.rs b/src/lib.rs index 46401cc..f5b5d87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::("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(|_| { @@ -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::("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) { @@ -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(|_| {