}
// returns a tuple with the value and its size
-fn http2_normalize_host(value: &[u8]) -> (Option<Vec<u8>>, usize) {
- match value.iter().position(|&x| x == b':') {
+fn http2_normalize_host(value: &[u8]) -> &[u8] {
+ match value.iter().position(|&x| x == b'@') {
Some(i) => {
- return (http2_lower(&value[..i]), i);
+ let value = &value[i+1..];
+ match value.iter().position(|&x| x == b':') {
+ Some(i) => {
+ return &value[..i];
+ }
+ None => {
+ return value;
+ }
+ }
}
None => {
- return (http2_lower(value), value.len());
+ match value.iter().position(|&x| x == b':') {
+ Some(i) => {
+ return &value[..i];
+ }
+ None => {
+ return value;
+ }
+ }
}
}
}
let r = http2_normalize_host(value);
// r is a tuple with the value and its size
// this is useful when we only take a substring (before the port)
- match r.0 {
+ match http2_lower(r) {
Some(normval) => {
// In case we needed some normalization,
// the transaction needs to take ownership of this normalized host
let idx = tx.escaped.len() - 1;
let resvalue = &tx.escaped[idx];
*buffer = resvalue.as_ptr(); //unsafe
- *buffer_len = r.1 as u32;
+ *buffer_len = resvalue.len() as u32;
return 1;
}
None => {
- *buffer = value.as_ptr(); //unsafe
- *buffer_len = r.1 as u32;
+ *buffer = r.as_ptr(); //unsafe
+ *buffer_len = r.len() as u32;
return 1;
}
}
fn test_http2_normalize_host() {
let buf0 = "aBC.com:1234".as_bytes();
let r0 = http2_normalize_host(buf0);
- match r0.0 {
- Some(r) => {
- assert_eq!(r, "abc.com".as_bytes().to_vec());
- }
- None => {
- panic!("Result should not have been None");
- }
- }
+ assert_eq!(r0, "aBC.com".as_bytes().to_vec());
let buf1 = "oisf.net".as_bytes();
let r1 = http2_normalize_host(buf1);
- match r1.0 {
- Some(r) => {
- panic!("Result should not have been None, not {:?}", r);
- }
- None => {}
- }
- assert_eq!(r1.1, "oisf.net".len());
+ assert_eq!(r1, "oisf.net".as_bytes().to_vec());
let buf2 = "localhost:3000".as_bytes();
let r2 = http2_normalize_host(buf2);
- match r2.0 {
- Some(r) => {
- panic!("Result should not have been None, not {:?}", r);
- }
- None => {}
- }
- assert_eq!(r2.1, "localhost".len());
+ assert_eq!(r2, "localhost".as_bytes().to_vec());
+ let buf3 = "user:pass@localhost".as_bytes();
+ let r3 = http2_normalize_host(buf3);
+ assert_eq!(r3, "localhost".as_bytes().to_vec());
+ let buf4 = "user:pass@localhost:123".as_bytes();
+ let r4 = http2_normalize_host(buf4);
+ assert_eq!(r4, "localhost".as_bytes().to_vec());
}
#[test]