Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`
(host: &str)
| 531 | /// `"alice.atomic.storage"` → `Some("alice")` |
| 532 | /// `"localhost"` → `None` |
| 533 | fn extract_subdomain(host: &str) -> Option<String> { |
| 534 | // Strip port if somehow present (Url should have parsed it out, but be safe). |
| 535 | let host = host.split(':').next().unwrap_or(host); |
| 536 | |
| 537 | let dot_pos = host.find('.')?; |
| 538 | let subdomain = &host[..dot_pos]; |
| 539 | |
| 540 | if subdomain.is_empty() { |
| 541 | return None; |
| 542 | } |
| 543 | |
| 544 | Some(subdomain.to_string()) |
| 545 | } |
| 546 | |
| 547 | #[cfg(test)] |
| 548 | mod tests { |
no test coverage detected