From ca5e520e7aa6d0a211e3c152c09095d35326ca12 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 15 Sep 2018 02:30:50 +0200 Subject: [PATCH] fix(http1): fix title-case option when header names have symbols Don't eat the first character in a header name if it's not a letter. Same thing after a `-` --- src/proto/h1/role.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index fb0a38c6f2..701ec0667d 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -943,6 +943,8 @@ fn title_case(dst: &mut Vec, name: &[u8]) { if let Some(c) = iter.next() { if *c >= b'a' && *c <= b'z' { dst.push(*c ^ b' '); + } else { + dst.push(*c); } } @@ -953,6 +955,8 @@ fn title_case(dst: &mut Vec, name: &[u8]) { if let Some(c) = iter.next() { if *c >= b'a' && *c <= b'z' { dst.push(*c ^ b' '); + } else { + dst.push(*c); } } } @@ -1371,6 +1375,7 @@ mod tests { let mut head = MessageHead::default(); head.headers.insert("content-length", HeaderValue::from_static("10")); head.headers.insert("content-type", HeaderValue::from_static("application/json")); + head.headers.insert("*-*", HeaderValue::from_static("o_o")); let mut vec = Vec::new(); Client::encode(Encode { @@ -1381,7 +1386,7 @@ mod tests { title_case_headers: true, }, &mut vec).unwrap(); - assert_eq!(vec, b"GET / HTTP/1.1\r\nContent-Length: 10\r\nContent-Type: application/json\r\n\r\n".to_vec()); + assert_eq!(vec, b"GET / HTTP/1.1\r\nContent-Length: 10\r\nContent-Type: application/json\r\n*-*: o_o\r\n\r\n".to_vec()); } #[test]