Skip to content

Commit

Permalink
Merge pull request #63 from SimonSapin/url
Browse files Browse the repository at this point in the history
Update the url crate to 2.0
  • Loading branch information
Alexey Galakhov authored Jul 24, 2019
2 parents 46629f7 + 4b1d89d commit 78cea49
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
homepage = "https://github.com/snapview/tungstenite-rs"
documentation = "https://docs.rs/tungstenite/0.8.1"
repository = "https://github.com/snapview/tungstenite-rs"
version = "0.8.1"
version = "0.9.0"

[features]
default = ["tls"]
Expand All @@ -25,7 +25,7 @@ input_buffer = "0.2.0"
log = "0.4.2"
rand = "0.6.4"
sha-1 = "0.8"
url = "1.7.0"
url = "2.0"
utf-8 = "0.7.2"

[dependencies.native-tls]
Expand Down
25 changes: 21 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,26 @@ pub fn connect_with_config<'t, Req: Into<Request<'t>>>(
) -> Result<(WebSocket<AutoStream>, Response)> {
let request: Request = request.into();
let mode = url_mode(&request.url)?;
let addrs = request.url.to_socket_addrs()?;
let host = request.url.host()
.ok_or_else(|| Error::Url("No host name in the URL".into()))?;
let port = request.url.port_or_known_default()
.ok_or_else(|| Error::Url("No port number in the URL".into()))?;
let addrs;
let addr;
let addrs = match host {
url::Host::Domain(domain) => {
addrs = (domain, port).to_socket_addrs()?;
addrs.as_slice()
}
url::Host::Ipv4(ip) => {
addr = (ip, port).into();
std::slice::from_ref(&addr)
}
url::Host::Ipv6(ip) => {
addr = (ip, port).into();
std::slice::from_ref(&addr)
}
};
let mut stream = connect_to_some(addrs, &request.url, mode)?;
NoDelay::set_nodelay(&mut stream, true)?;
client_with_config(request, stream, config)
Expand Down Expand Up @@ -115,9 +134,7 @@ pub fn connect<'t, Req: Into<Request<'t>>>(request: Req)
connect_with_config(request, None)
}

fn connect_to_some<A>(addrs: A, url: &Url, mode: Mode) -> Result<AutoStream>
where A: Iterator<Item=SocketAddr>
{
fn connect_to_some(addrs: &[SocketAddr], url: &Url, mode: Mode) -> Result<AutoStream> {
let domain = url.host_str().ok_or_else(|| Error::Url("No host name in the URL".into()))?;
for addr in addrs {
debug!("Trying to contact {} at {}...", url, addr);
Expand Down

0 comments on commit 78cea49

Please sign in to comment.