|
68 | 68 | H: Iterator<Item = (S, &'a Vec<u8>)>,
|
69 | 69 | {
|
70 | 70 | // TODO: valid that host doesn't have port
|
71 |
| - // TODO: support adding ad-hoc headers |
72 | 71 |
|
73 |
| - let authority = format!("{host}:{port}"); |
| 72 | + let authority = if host.parse::<std::net::Ipv6Addr>().is_ok() { |
| 73 | + format!("[{host}]:{port}") |
| 74 | + } else { |
| 75 | + format!("{host}:{port}") |
| 76 | + }; |
| 77 | + |
74 | 78 | let req = http::request::Builder::new()
|
75 | 79 | .version(http::Version::HTTP_11)
|
76 | 80 | .method(http::method::Method::CONNECT)
|
@@ -217,6 +221,19 @@ mod test_sync {
|
217 | 221 | assert_eq!(req.headers.get("Host").unwrap(), "pingora.org:123");
|
218 | 222 | assert_eq!(req.headers.get("foo").unwrap(), "bar");
|
219 | 223 | }
|
| 224 | + |
| 225 | + #[test] |
| 226 | + fn test_generate_connect_header_ipv6() { |
| 227 | + let mut headers = BTreeMap::new(); |
| 228 | + headers.insert(String::from("foo"), b"bar".to_vec()); |
| 229 | + let req = generate_connect_header("::1", 123, headers.iter()).unwrap(); |
| 230 | + |
| 231 | + assert_eq!(req.method, http::method::Method::CONNECT); |
| 232 | + assert_eq!(req.uri.authority().unwrap(), "[::1]:123"); |
| 233 | + assert_eq!(req.headers.get("Host").unwrap(), "[::1]:123"); |
| 234 | + assert_eq!(req.headers.get("foo").unwrap(), "bar"); |
| 235 | + } |
| 236 | + |
220 | 237 | #[test]
|
221 | 238 | fn test_request_to_wire_auth_form() {
|
222 | 239 | let new_request = http::Request::builder()
|
|
0 commit comments