diff options
author | Yuchen Wu <[email protected]> | 2024-07-25 10:41:59 -0700 |
---|---|---|
committer | Andrew Hauck <[email protected]> | 2024-08-09 14:30:49 -0700 |
commit | 9f50e6ccb09db2940eec6fc170a1e9e9b14a95d0 (patch) | |
tree | 0929b21d3715061ba74e49550cbdb408fa9c1176 | |
parent | 29746f6968429dac94eec7decce83338cbe61304 (diff) | |
download | pingora-9f50e6ccb09db2940eec6fc170a1e9e9b14a95d0.tar.gz pingora-9f50e6ccb09db2940eec6fc170a1e9e9b14a95d0.zip |
Handle bare IPv6 address in raw connect Host
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/protocols/raw_connect.rs | 21 |
2 files changed, 20 insertions, 3 deletions
@@ -1 +1 @@ -c90e4ce2596840c60b5ff1737e2141447e5953e1 +d04fc15ccce78032d84491744e29641f3e577347
\ No newline at end of file diff --git a/pingora-core/src/protocols/raw_connect.rs b/pingora-core/src/protocols/raw_connect.rs index df82413..4aeb10c 100644 --- a/pingora-core/src/protocols/raw_connect.rs +++ b/pingora-core/src/protocols/raw_connect.rs @@ -68,9 +68,13 @@ where H: Iterator<Item = (S, &'a Vec<u8>)>, { // TODO: valid that host doesn't have port - // TODO: support adding ad-hoc headers - let authority = format!("{host}:{port}"); + let authority = if host.parse::<std::net::Ipv6Addr>().is_ok() { + format!("[{host}]:{port}") + } else { + format!("{host}:{port}") + }; + let req = http::request::Builder::new() .version(http::Version::HTTP_11) .method(http::method::Method::CONNECT) @@ -217,6 +221,19 @@ mod test_sync { assert_eq!(req.headers.get("Host").unwrap(), "pingora.org:123"); assert_eq!(req.headers.get("foo").unwrap(), "bar"); } + + #[test] + fn test_generate_connect_header_ipv6() { + let mut headers = BTreeMap::new(); + headers.insert(String::from("foo"), b"bar".to_vec()); + let req = generate_connect_header("::1", 123, headers.iter()).unwrap(); + + assert_eq!(req.method, http::method::Method::CONNECT); + assert_eq!(req.uri.authority().unwrap(), "[::1]:123"); + assert_eq!(req.headers.get("Host").unwrap(), "[::1]:123"); + assert_eq!(req.headers.get("foo").unwrap(), "bar"); + } + #[test] fn test_request_to_wire_auth_form() { let new_request = http::Request::builder() |