MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_host

Function parse_host

crates/openshell-server/src/service_routing.rs:85–106  ·  view source on GitHub ↗
(host: &str, config: &ServiceRoutingConfig)

Source from the content-addressed store, hash-verified

83}
84
85pub fn parse_host(host: &str, config: &ServiceRoutingConfig) -> Option<(String, String)> {
86 let host = host.split_once(':').map_or(host, |(name, _)| name);
87 for base_domain in &config.base_domains {
88 let expected_suffix = format!(".{base_domain}");
89 let Some(encoded) = host.strip_suffix(&expected_suffix) else {
90 continue;
91 };
92 let (sandbox, service) = if let Some((sandbox, service)) = encoded.split_once("--") {
93 if service.is_empty() || service.contains("--") {
94 return None;
95 }
96 (sandbox, service)
97 } else {
98 (encoded, "")
99 };
100 if sandbox.is_empty() || sandbox.contains("--") {
101 return None;
102 }
103 return Some((sandbox.to_string(), service.to_string()));
104 }
105 None
106}
107
108pub fn is_sandbox_service_request<B>(req: &Request<B>, config: &ServiceRoutingConfig) -> bool {
109 request_host(req).is_some_and(|host| parse_host(host, config).is_some())

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected