(server_url: &str)
| 70 | |
| 71 | impl HttpEndpoint { |
| 72 | fn parse(server_url: &str) -> anyhow::Result<Self> { |
| 73 | let without_scheme = server_url |
| 74 | .trim_end_matches('/') |
| 75 | .strip_prefix("http://") |
| 76 | .ok_or_else(|| anyhow::anyhow!("Only http:// server URLs are supported."))?; |
| 77 | let authority = without_scheme |
| 78 | .split('/') |
| 79 | .next() |
| 80 | .filter(|value| !value.is_empty()) |
| 81 | .ok_or_else(|| anyhow::anyhow!("Server URL must include a host."))?; |
| 82 | let (host, port) = if let Some(host) = authority.strip_prefix('[') { |
| 83 | let (host, rest) = host |
| 84 | .split_once(']') |
| 85 | .ok_or_else(|| anyhow::anyhow!("Invalid IPv6 server URL host."))?; |
| 86 | let port = rest |
| 87 | .strip_prefix(':') |
| 88 | .map(parse_port) |
| 89 | .transpose()? |
| 90 | .unwrap_or(80); |
| 91 | (host.to_owned(), port) |
| 92 | } else if let Some((host, port)) = authority.rsplit_once(':') { |
| 93 | (host.to_owned(), parse_port(port)?) |
| 94 | } else { |
| 95 | (authority.to_owned(), 80) |
| 96 | }; |
| 97 | Ok(Self { host, port }) |
| 98 | } |
| 99 | |
| 100 | fn host_header(&self) -> String { |
| 101 | if self.host.contains(':') { |
no test coverage detected