Skip to content

Commit

Permalink
fix(client): Fix the header sending order, set accept before request (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 authored Sep 3, 2024
1 parent c787890 commit 2beae56
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ impl ClientBuilder {
///
/// This is the same as `Client::builder()`.
pub fn new() -> ClientBuilder {
let mut headers: HeaderMap<HeaderValue> = HeaderMap::with_capacity(2);
headers.insert(ACCEPT, HeaderValue::from_static("*/*"));

ClientBuilder {
config: Config {
error: None,
accepts: Accepts::default(),
headers,
headers: HeaderMap::with_capacity(1),
headers_order: None,
connect_timeout: None,
connection_verbose: false,
Expand Down Expand Up @@ -1352,14 +1349,22 @@ impl Client {
return Pending::new_err(error::url_bad_scheme(url));
}

let mut accept = false;

// insert default headers in the request headers
// without overwriting already appended headers.
for (key, value) in &self.inner.headers {
if let Entry::Vacant(entry) = headers.entry(key) {
accept = ACCEPT.eq(key);
entry.insert(value.clone());
}
}

// Default accpet
if accept || headers.is_empty() {
headers.insert(ACCEPT, HeaderValue::from_static("*/*"));
}

// Add cookies from the cookie store.
#[cfg(feature = "cookies")]
{
Expand Down

0 comments on commit 2beae56

Please sign in to comment.