MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / into_base_path

Function into_base_path

api-server/src/client/mod.rs:59–87  ·  view source on GitHub ↗

Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.

(
    input: impl TryInto<Uri, Error = hyper::http::uri::InvalidUri>,
    correct_scheme: Option<&'static str>,
)

Source from the content-addressed store, hash-verified

57
58/// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes.
59fn into_base_path(
60 input: impl TryInto<Uri, Error = hyper::http::uri::InvalidUri>,
61 correct_scheme: Option<&'static str>,
62) -> Result<String, ClientInitError> {
63 // First convert to Uri, since a base path is a subset of Uri.
64 let uri = input.try_into()?;
65
66 let scheme = uri.scheme_str().ok_or(ClientInitError::InvalidScheme)?;
67
68 // Check the scheme if necessary
69 if let Some(correct_scheme) = correct_scheme {
70 if scheme != correct_scheme {
71 return Err(ClientInitError::InvalidScheme);
72 }
73 }
74
75 let host = uri.host().ok_or(ClientInitError::MissingHost)?;
76 let port = uri
77 .port_u16()
78 .map(|x| format!(":{}", x))
79 .unwrap_or_default();
80 Ok(format!(
81 "{}://{}{}{}",
82 scheme,
83 host,
84 port,
85 uri.path().trim_end_matches('/')
86 ))
87}
88
89/// A client that implements the API by making HTTP calls out to a server.
90pub struct Client<S, C>

Callers 3

try_newMethod · 0.70

Calls 2

try_intoMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected