Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`
(host: &str)
| 578 | /// `"alice.atomic.storage"` → `Some("alice")` |
| 579 | /// `"localhost"` → `None` |
| 580 | fn extract_subdomain(host: &str) -> Option<String> { |
| 581 | // Strip port if somehow present (Url should have parsed it out, but be safe). |
| 582 | let host = host.split(':').next().unwrap_or(host); |
| 583 | |
| 584 | let dot_pos = host.find('.')?; |
| 585 | let subdomain = &host[..dot_pos]; |
| 586 | |
| 587 | if subdomain.is_empty() { |
| 588 | return None; |
| 589 | } |
| 590 | |
| 591 | Some(subdomain.to_string()) |
| 592 | } |
| 593 | |
| 594 | #[cfg(test)] |
| 595 | mod tests { |
no test coverage detected