MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / parse

Method parse

packages/server/src/main/http.rs:72–98  ·  view source on GitHub ↗
(server_url: &str)

Source from the content-addressed store, hash-verified

70
71impl HttpEndpoint {
72 fn parse(server_url: &str) -> anyhow::Result<Self> {
73 let without_scheme = server_url
74 .trim_end_matches('/')
75 .strip_prefix("http://")
76 .ok_or_else(|| anyhow::anyhow!("Only http:// server URLs are supported."))?;
77 let authority = without_scheme
78 .split('/')
79 .next()
80 .filter(|value| !value.is_empty())
81 .ok_or_else(|| anyhow::anyhow!("Server URL must include a host."))?;
82 let (host, port) = if let Some(host) = authority.strip_prefix('[') {
83 let (host, rest) = host
84 .split_once(']')
85 .ok_or_else(|| anyhow::anyhow!("Invalid IPv6 server URL host."))?;
86 let port = rest
87 .strip_prefix(':')
88 .map(parse_port)
89 .transpose()?
90 .unwrap_or(80);
91 (host.to_owned(), port)
92 } else if let Some((host, port)) = authority.rsplit_once(':') {
93 (host.to_owned(), parse_port(port)?)
94 } else {
95 (authority.to_owned(), 80)
96 };
97 Ok(Self { host, port })
98 }
99
100 fn host_header(&self) -> String {
101 if self.host.contains(':') {

Callers 2

serve_static_innerFunction · 0.45
run_batch_stepFunction · 0.45

Calls 2

parse_portFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected