Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`
(host: &str)
| 649 | /// `"alice.atomic.storage"` → `Some("alice")` |
| 650 | /// `"localhost"` → `None` |
| 651 | fn extract_subdomain(host: &str) -> Option<String> { |
| 652 | // Strip port if somehow present (Url should have parsed it out, but be safe). |
| 653 | let host = host.split(':').next().unwrap_or(host); |
| 654 | |
| 655 | let dot_pos = host.find('.')?; |
| 656 | let subdomain = &host[..dot_pos]; |
| 657 | |
| 658 | if subdomain.is_empty() { |
| 659 | return None; |
| 660 | } |
| 661 | |
| 662 | Some(subdomain.to_string()) |
| 663 | } |
| 664 | |
| 665 | #[cfg(test)] |
| 666 | mod tests { |
no test coverage detected