client: Fix websocket url parsing (#589)
This commit is contained in:
parent
ceb80b0a04
commit
84c3288f32
|
@ -40,6 +40,14 @@ impl FromStr for Cluster {
|
||||||
ws_url.set_port(Some(8900))
|
ws_url.set_port(Some(8900))
|
||||||
.map_err(|_| anyhow!("Unable to set port"))?;
|
.map_err(|_| anyhow!("Unable to set port"))?;
|
||||||
}
|
}
|
||||||
|
if ws_url.scheme() == "https" {
|
||||||
|
ws_url.set_scheme("wss")
|
||||||
|
.map_err(|_| anyhow!("Unable to set scheme"))?;
|
||||||
|
} else {
|
||||||
|
ws_url.set_scheme("ws")
|
||||||
|
.map_err(|_| anyhow!("Unable to set scheme"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(Cluster::Custom(http_url.to_string(), ws_url.to_string()))
|
Ok(Cluster::Custom(http_url.to_string(), ws_url.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -116,7 +124,7 @@ mod tests {
|
||||||
let url = "http://my-url.com:7000/";
|
let url = "http://my-url.com:7000/";
|
||||||
let cluster = Cluster::from_str(url).unwrap();
|
let cluster = Cluster::from_str(url).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Cluster::Custom(url.to_string(), "http://my-url.com:7001/".to_string()),
|
Cluster::Custom(url.to_string(), "ws://my-url.com:7001/".to_string()),
|
||||||
cluster
|
cluster
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +134,26 @@ mod tests {
|
||||||
let url = "http://my-url.com/";
|
let url = "http://my-url.com/";
|
||||||
let cluster = Cluster::from_str(url).unwrap();
|
let cluster = Cluster::from_str(url).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Cluster::Custom(url.to_string(), "http://my-url.com:8900/".to_string()),
|
Cluster::Custom(url.to_string(), "ws://my-url.com:8900/".to_string()),
|
||||||
|
cluster
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_https_port() {
|
||||||
|
let url = "https://my-url.com:7000/";
|
||||||
|
let cluster = Cluster::from_str(url).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Cluster::Custom(url.to_string(), "wss://my-url.com:7001/".to_string()),
|
||||||
|
cluster
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_https_no_port() {
|
||||||
|
let url = "https://my-url.com/";
|
||||||
|
let cluster = Cluster::from_str(url).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Cluster::Custom(url.to_string(), "wss://my-url.com:8900/".to_string()),
|
||||||
cluster
|
cluster
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue