Skip to main content

hyper_util/client/
mod.rs

1//! HTTP client utilities
2
3/// Legacy implementations of `connect` module and `Client`
4#[cfg(feature = "client-legacy")]
5pub mod legacy;
6
7#[cfg(feature = "client-pool")]
8pub mod pool;
9
10#[cfg(feature = "client-proxy")]
11pub mod proxy;
12
13#[cfg(any(feature = "client-legacy", feature = "client-proxy"))]
14fn strip_ipv6_brackets(host: &str) -> &str {
15    host.strip_prefix('[')
16        .and_then(|host| host.strip_suffix(']'))
17        .unwrap_or(host)
18}
19
20#[cfg(all(test, any(feature = "client-legacy", feature = "client-proxy")))]
21mod tests {
22    use super::strip_ipv6_brackets;
23
24    #[test]
25    fn test_strip_ipv6_brackets() {
26        assert_eq!(strip_ipv6_brackets("[::1]"), "::1");
27        assert_eq!(strip_ipv6_brackets("::1"), "::1");
28        assert_eq!(strip_ipv6_brackets("example.com"), "example.com");
29        assert_eq!(strip_ipv6_brackets("[example.com"), "[example.com");
30        assert_eq!(strip_ipv6_brackets("example.com]"), "example.com]");
31    }
32}