-
Notifications
You must be signed in to change notification settings - Fork 123
Lowercaseify Nexus request headers #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| use std::collections::HashMap; | ||
|
|
||
| use prost::{EncodeError, Message}; | ||
|
|
||
| pub trait TryIntoOrNone<F, T> { | ||
|
|
@@ -26,3 +28,13 @@ pub fn pack_any<T: Message>( | |
| Message::encode(msg, &mut value)?; | ||
| Ok(prost_wkt_types::Any { type_url, value }) | ||
| } | ||
|
|
||
| /// Given a header map, lowercase all the keys and return it as a new map. | ||
| /// Any keys that are duplicated after lowercasing will clobber each other in undefined ordering. | ||
| pub fn normalize_http_headers(headers: HashMap<String, String>) -> HashMap<String, String> { | ||
| let mut new_headers = HashMap::new(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be better to accept a mutable map if we can, but if we must do it this way, would recommend either using an iter approach (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot mutate hashmap keys. |
||
| for (header_key, val) in headers.into_iter() { | ||
| new_headers.insert(header_key.to_lowercase(), val); | ||
| } | ||
| new_headers | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we
std::mem::takehere? Just for safety, to make sure that memory is cleared out?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just accept a mutable hash map reference in the normalize helper?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows me to own the old map, therefore I can call
into_iterand avoid copying all the values