(host: &str, config: &ServiceRoutingConfig)
| 83 | } |
| 84 | |
| 85 | pub 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 | |
| 108 | pub 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()) |
no test coverage detected