MCPcopy Create free account
hub / github.com/Recordscript/recordscript / parse

Method parse

libs/hbb_common/src/proxy.rs:192–220  ·  view source on GitHub ↗
(url: Url)

Source from the content-addressed store, hash-verified

190 }
191
192 fn parse(url: Url) -> Result<Self, ProxyError> {
193 use url::Position;
194
195 // Resolve URL to a host and port
196 let to_addr = || {
197 let addrs = url.socket_addrs(|| match url.scheme() {
198 "socks5" => Some(1080),
199 _ => None,
200 })?;
201 addrs
202 .into_iter()
203 .next()
204 .ok_or_else(|| ProxyError::UrlParseScheme(url::ParseError::EmptyHost))
205 };
206
207 let mut scheme: Self = match url.scheme() {
208 "http" => Self::http(&url[Position::BeforeHost..Position::AfterPort])?,
209 "https" => Self::https(&url[Position::BeforeHost..Position::AfterPort])?,
210 "socks5" => Self::socks5(to_addr()?)?,
211 e => return Err(ProxyError::UrlBadScheme(e.to_string())),
212 };
213
214 if let Some(pwd) = url.password() {
215 let username = url.username();
216 scheme.set_basic_auth(username, pwd);
217 }
218
219 Ok(scheme)
220 }
221 pub async fn socket_addrs(&self) -> Result<SocketAddr, ProxyError> {
222 info!("Resolving socket address");
223 match self {

Callers 6

increase_portFunction · 0.80
get_double_stringMethod · 0.80
test_mangle2Function · 0.80
recv_and_check_responseFunction · 0.80
transcribeMethod · 0.80

Calls 4

socket_addrsMethod · 0.80
to_stringMethod · 0.80
set_basic_authMethod · 0.80
nextMethod · 0.45

Tested by 1

test_mangle2Function · 0.64