-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathnetstat.rs
62 lines (60 loc) · 1.88 KB
/
netstat.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use reqwest::Url;
use std::{
collections::HashSet,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
};
use url::Host;
use crate::command::dev::legacy::protocol::SubgraphUrl;
pub fn normalize_loopback_urls(url: &SubgraphUrl) -> Vec<SubgraphUrl> {
let hosts = match url.host() {
Some(host) => match host {
Host::Ipv4(ip) => {
if &ip.to_string() == "::" {
vec![
IpAddr::V4(ip).to_string(),
IpAddr::V4(Ipv4Addr::LOCALHOST).to_string(),
]
} else {
vec![IpAddr::V4(ip).to_string()]
}
}
Host::Ipv6(ip) => {
if &ip.to_string() == "::" || &ip.to_string() == "::1" {
vec![
IpAddr::V6(ip).to_string(),
IpAddr::V6(Ipv6Addr::LOCALHOST).to_string(),
]
} else {
vec![IpAddr::V6(ip).to_string()]
}
}
Host::Domain(domain) => {
if domain == "localhost" {
vec![
IpAddr::V4(Ipv4Addr::LOCALHOST).to_string(),
IpAddr::V6(Ipv6Addr::LOCALHOST).to_string(),
"[::]".to_string(),
"0.0.0.0".to_string(),
]
} else {
vec![domain.to_string()]
}
}
},
None => Vec::new(),
};
if hosts.is_empty() {
vec![url.clone()]
} else {
Vec::from_iter(
hosts
.iter()
.map(|host| {
let mut url = url.clone();
let _ = url.set_host(Some(host));
url
})
.collect::<HashSet<Url>>(),
)
}
}