MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_subdomain

Function extract_subdomain

atomic-remote/src/auth/mod.rs:660–672  ·  view source on GitHub ↗

Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`

(host: &str)

Source from the content-addressed store, hash-verified

658/// `"alice.atomic.storage"` → `Some("alice")`
659/// `"localhost"` → `None`
660fn extract_subdomain(host: &str) -> Option<String> {
661 // Strip port if somehow present (Url should have parsed it out, but be safe).
662 let host = host.split(':').next().unwrap_or(host);
663
664 let dot_pos = host.find('.')?;
665 let subdomain = &host[..dot_pos];
666
667 if subdomain.is_empty() {
668 return None;
669 }
670
671 Some(subdomain.to_string())
672}
673
674#[cfg(test)]
675mod tests {

Callers 1

Calls 2

nextMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected