Skip to content

Commit

Permalink
Upgrade to url v2.0
Browse files Browse the repository at this point in the history
The upgrade is mostly smooth, except support for converting a URL to
socket addresses has annoyingly been removed.
  • Loading branch information
benesch committed Jul 30, 2019
1 parent de3f91c commit 40324fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ remote_list = ["native-tls"]
error-chain = "0.12"
idna = "0.1"
regex = "1.0"
url = "1.7"
url = "2.0"
lazy_static = "1.0"

[dependencies.native-tls]
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ error_chain! {

NoHost { }

NoPort { }

InvalidHost { }

InvalidEmail { }
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,16 @@ impl IntoUrl for String {
#[cfg(feature = "remote_list")]
fn request<U: IntoUrl>(u: U) -> Result<String> {
let url = u.into_url()?;
let addr = url.with_default_port(|_| Err(()))?;
let host = match url.host_str() {
Some(host) => host,
None => { return Err(ErrorKind::NoHost.into()); }
};
let port = match url.port_or_known_default() {
Some(port) => port,
None => { return Err(ErrorKind::NoPort.into()); }
};
let data = format!("GET {} HTTP/1.0\r\nHost: {}\r\n\r\n", url.path(), host);
let addr = format!("{}:{}", host, port);
let stream = TcpStream::connect(addr)?;
let timeout = Duration::from_secs(2);
stream.set_read_timeout(Some(timeout))?;
Expand Down

0 comments on commit 40324fa

Please sign in to comment.