| 2833 | /// if the URI cannot be parsed. |
| 2834 | #[cfg(test)] |
| 2835 | fn extract_host_from_uri(uri: &str) -> String { |
| 2836 | // Absolute-form URIs look like "http://host[:port]/path" |
| 2837 | // Strip the scheme prefix, then extract the authority (host[:port]) before the first '/'. |
| 2838 | let after_scheme = uri.find("://").map_or(uri, |i| &uri[i + 3..]); |
| 2839 | let authority = after_scheme.split('/').next().unwrap_or(after_scheme); |
| 2840 | // Strip port if present (handle IPv6 bracket notation) |
| 2841 | let host = if authority.starts_with('[') { |
| 2842 | // IPv6: [::1]:port |
| 2843 | authority.find(']').map_or(authority, |i| &authority[..=i]) |
| 2844 | } else { |
| 2845 | authority.split(':').next().unwrap_or(authority) |
| 2846 | }; |
| 2847 | if host.is_empty() { |
| 2848 | "unknown".to_string() |
| 2849 | } else { |
| 2850 | host.to_string() |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | /// Parse an absolute-form proxy request URI into its components. |
| 2855 | /// |