Skip to content
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

address more header names that are not canonicalized before use #1048

Merged
merged 1 commit into from
Aug 30, 2022

Conversation

bmc-msft
Copy link
Contributor

@bmc-msft bmc-msft commented Aug 29, 2022

Because Header Names are canonicalized to lowercase, use of these headers broke when the headername implementation changed.

@bmc-msft
Copy link
Contributor Author

It would be great if we could find a way to ensure header names are always canonicalized moving forwards. These were not caught during the shift from http::Request to azure_core::Request as part of #833.

For reference, our existing methods for creating HeaderName, which only check when we're creating them from String or Cow, but not when making static versions:

impl HeaderName {
pub const fn from_static(s: &'static str) -> Self {
Self(std::borrow::Cow::Borrowed(s))
}
fn from_cow<C>(c: C) -> Self
where
C: Into<std::borrow::Cow<'static, str>>,
{
let c = c.into();
assert!(
c.chars().all(|c| c.is_lowercase() || !c.is_alphabetic()),
"header names must be lowercase: {c}"
);
Self(c)
}
pub fn as_str(&self) -> &str {
self.0.as_ref()
}
}
impl From<&'static str> for HeaderName {
fn from(s: &'static str) -> Self {
Self::from_cow(s)
}
}
impl From<String> for HeaderName {
fn from(s: String) -> Self {
Self::from_cow(s.to_lowercase())
}
}

@bmc-msft bmc-msft merged commit ffd7624 into Azure:main Aug 30, 2022
@bmc-msft bmc-msft deleted the fix-more-broken-http-header-names branch August 30, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants