Skip to content

Commit

Permalink
Sort incoming headers
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 17, 2024
1 parent 145727b commit 868c3d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions ehttp/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn fetch_blocking(request: &Request) -> crate::Result<Response> {
headers.insert(key, value.to_owned());
}
}
headers.sort(); // It reads nicer, and matches web backend.

let mut reader = resp.into_reader();
let mut bytes = vec![];
Expand Down
1 change: 1 addition & 0 deletions ehttp/src/streaming/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn fetch_streaming_blocking(
headers.insert(key.to_ascii_lowercase(), value.to_owned());
}
}
headers.sort(); // It reads nicer, and matches web backend.

let response = PartialResponse {
url,
Expand Down
9 changes: 9 additions & 0 deletions ehttp/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ impl Headers {
.filter(move |(k, _)| k.to_lowercase() == key)
.map(|(_, v)| v.as_str())
}

/// Sort the headers by key.
///
/// This makes the headers easier to read when printed out.
///
/// `ehttp` will sort the headers in the responses.
pub fn sort(&mut self) {
self.headers.sort_by(|a, b| a.0.cmp(&b.0));
}
}

impl IntoIterator for Headers {
Expand Down

0 comments on commit 868c3d6

Please sign in to comment.