From 40324fa21590d14630a152bbf39dc0e12b3d27a0 Mon Sep 17 00:00:00 2001
From: Nikhil Benesch <nikhil.benesch@gmail.com>
Date: Tue, 30 Jul 2019 11:44:43 -0400
Subject: [PATCH] Upgrade to url v2.0

The upgrade is mostly smooth, except support for converting a URL to
socket addresses has annoyingly been removed.
---
 Cargo.toml    | 2 +-
 src/errors.rs | 2 ++
 src/lib.rs    | 6 +++++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/errors.rs b/src/errors.rs
index 4c96fff..ff230f4 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -18,6 +18,8 @@ error_chain! {
 
         NoHost { }
 
+        NoPort { }
+
         InvalidHost { }
 
         InvalidEmail { }
diff --git a/src/lib.rs b/src/lib.rs
index 0619514..2fbe827 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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))?;
