MCPcopy Create free account
hub / github.com/AI45Lab/Code / parse_proxy_url

Function parse_proxy_url

core/src/tools/builtin/web_search.rs:406–443  ·  view source on GitHub ↗

Parse a proxy URL string like "http://host:port" into a ProxyConfig

(url: &str)

Source from the content-addressed store, hash-verified

404
405/// Parse a proxy URL string like "http://host:port" into a ProxyConfig
406fn parse_proxy_url(url: &str) -> Option<ProxyConfig> {
407 let url = url.trim();
408 if url.is_empty() {
409 return None;
410 }
411
412 // Parse scheme
413 let (scheme, rest) = if let Some(rest) = url.strip_prefix("socks5://") {
414 ("socks5", rest)
415 } else if let Some(rest) = url.strip_prefix("https://") {
416 ("https", rest)
417 } else if let Some(rest) = url.strip_prefix("http://") {
418 ("http", rest)
419 } else {
420 ("http", url)
421 };
422
423 // Parse host:port
424 let (host, port) = if let Some(colon_pos) = rest.rfind(':') {
425 let host = &rest[..colon_pos];
426 let port_str = &rest[colon_pos + 1..];
427 match port_str.parse::<u16>() {
428 Ok(p) => (host, p),
429 Err(_) => return None,
430 }
431 } else {
432 return None;
433 };
434
435 let mut config = ProxyConfig::new(host, port);
436 config = match scheme {
437 "socks5" => config.with_protocol(a3s_search::proxy::ProxyProtocol::Socks5),
438 "https" => config.with_protocol(a3s_search::proxy::ProxyProtocol::Https),
439 _ => config, // default is Http
440 };
441
442 Some(config)
443}
444
445#[cfg(test)]
446mod tests {

Callers 3

executeMethod · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by 2