Prevent the use of uppercase letters in HeaderName::from_static
@@ -173,6 +173,7 @@ pub struct HeaderName(std::borrow::Cow<'static, str>);
impl HeaderName {
pub const fn from_static(s: &'static str) -> Self {
+ ensure_no_uppercase(s);
Self(std::borrow::Cow::Borrowed(s))
}
@@ -193,6 +194,19 @@ impl HeaderName {
}
}
+/// Ensures the supplied string does not contain any uppercase ascii characters
+const fn ensure_no_uppercase(s: &str) {
+ let bytes = s.as_bytes();
+ let mut i = 0;
+ while i < bytes.len() {
+ let byte = bytes[i];
+ if byte >= 65u8 && byte <= 90u8 {
+ panic!("header names must not contain any uppercase letters");
+ }
+ i += 1;
+ }
+}
+
impl From<&'static str> for HeaderName {
fn from(s: &'static str) -> Self {
Self::from_cow(s)
