Skip to content

Commit 812c1b7

Browse files
committed
Fix header comparison with strings
This should be insensitive of case
1 parent 48ab6e5 commit 812c1b7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/headers/header_name.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,37 @@ impl<'a> std::convert::TryFrom<&'a str> for HeaderName {
7373

7474
impl PartialEq<str> for HeaderName {
7575
fn eq(&self, other: &str) -> bool {
76-
self.0 == other
76+
match HeaderName::from_str(other) {
77+
Err(_) => return false,
78+
Ok(other) => self == &other,
79+
}
7780
}
7881
}
7982

8083
impl<'a> PartialEq<&'a str> for HeaderName {
8184
fn eq(&self, other: &&'a str) -> bool {
82-
&self.0 == other
85+
match HeaderName::from_str(other) {
86+
Err(_) => return false,
87+
Ok(other) => self == &other,
88+
}
8389
}
8490
}
8591

8692
impl PartialEq<String> for HeaderName {
8793
fn eq(&self, other: &String) -> bool {
88-
&self.0 == other
94+
match HeaderName::from_str(&other) {
95+
Err(_) => return false,
96+
Ok(other) => self == &other,
97+
}
8998
}
9099
}
91100

92101
impl<'a> PartialEq<&String> for HeaderName {
93102
fn eq(&self, other: &&String) -> bool {
94-
&&self.0 == other
103+
match HeaderName::from_str(other) {
104+
Err(_) => return false,
105+
Ok(other) => self == &other,
106+
}
95107
}
96108
}
97109

@@ -120,5 +132,8 @@ mod tests {
120132
assert_eq!(&static_header, "hello");
121133
assert_eq!(static_header, String::from("hello"));
122134
assert_eq!(static_header, &String::from("hello"));
135+
136+
// Must validate regardless of casing.
137+
assert_eq!(static_header, &String::from("Hello"));
123138
}
124139
}

0 commit comments

Comments
 (0)