support WSS IP Urls
This commit is contained in:
parent
5757a5badf
commit
c4b8985263
@ -54,11 +54,12 @@ impl fmt::Display for DialInfo {
|
|||||||
SplitUrlHost::Hostname(_) => {
|
SplitUrlHost::Hostname(_) => {
|
||||||
write!(f, "wss|{}|{}", di.socket_address.ip_addr(), di.request)
|
write!(f, "wss|{}|{}", di.socket_address.ip_addr(), di.request)
|
||||||
}
|
}
|
||||||
SplitUrlHost::IpAddr(_) => {
|
SplitUrlHost::IpAddr(a) => {
|
||||||
panic!(
|
if di.socket_address.ip_addr() == a {
|
||||||
"secure websockets can not use ip address in request: {}",
|
write!(f, "wss|{}", di.request)
|
||||||
di.request
|
} else {
|
||||||
);
|
panic!("resolved address does not match url: {}", di.request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,18 +120,23 @@ impl FromStr for DialInfo {
|
|||||||
}
|
}
|
||||||
let url_port = split_url.port.unwrap_or(443u16);
|
let url_port = split_url.port.unwrap_or(443u16);
|
||||||
|
|
||||||
let (a, rest) = rest.split_once('|').ok_or_else(|| {
|
match rest.split_once('|') {
|
||||||
VeilidAPIError::parse_error(
|
Some((sa, rest)) => {
|
||||||
"DialInfo::from_str missing socket address '|' separator",
|
let address = Address::from_str(sa)?;
|
||||||
s,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let address = Address::from_str(a)?;
|
DialInfo::try_wss(
|
||||||
DialInfo::try_wss(
|
SocketAddress::new(address, url_port),
|
||||||
SocketAddress::new(address, url_port),
|
format!("wss://{}", rest),
|
||||||
format!("wss://{}", rest),
|
)
|
||||||
)
|
}
|
||||||
|
None => {
|
||||||
|
let address = Address::from_str(&split_url.host.to_string())?;
|
||||||
|
DialInfo::try_wss(
|
||||||
|
SocketAddress::new(address, url_port),
|
||||||
|
format!("wss://{}", rest),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => Err(VeilidAPIError::parse_error(
|
_ => Err(VeilidAPIError::parse_error(
|
||||||
"DialInfo::from_str has invalid scheme",
|
"DialInfo::from_str has invalid scheme",
|
||||||
@ -196,11 +202,13 @@ impl DialInfo {
|
|||||||
if url_port != socket_address.port() {
|
if url_port != socket_address.port() {
|
||||||
apibail_parse_error!("socket address port doesn't match url port", url);
|
apibail_parse_error!("socket address port doesn't match url port", url);
|
||||||
}
|
}
|
||||||
if !matches!(split_url.host, SplitUrlHost::Hostname(_)) {
|
if let SplitUrlHost::IpAddr(a) = split_url.host {
|
||||||
apibail_parse_error!(
|
if socket_address.ip_addr() != a {
|
||||||
"WSS url can not use address format, only hostname format",
|
apibail_parse_error!(
|
||||||
url
|
format!("request address does not match socket address: {}", a),
|
||||||
);
|
socket_address
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(Self::WSS(DialInfoWSS {
|
Ok(Self::WSS(DialInfoWSS {
|
||||||
socket_address: socket_address.canonical(),
|
socket_address: socket_address.canonical(),
|
||||||
|
Loading…
Reference in New Issue
Block a user