Skip to content

Commit 6e08201

Browse files
committed
Remove DNS-related functionality
1 parent 51d6b33 commit 6e08201

File tree

3 files changed

+4
-176
lines changed

3 files changed

+4
-176
lines changed

src/host.rs

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use parser::{ParseError, ParseResult};
1111
use percent_encoding::{percent_decode, utf8_percent_encode, SIMPLE_ENCODE_SET};
1212
use std::cmp;
1313
use std::fmt::{self, Formatter};
14-
use std::io;
15-
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
16-
use std::vec;
14+
use std::net::{Ipv4Addr, Ipv6Addr};
1715

1816
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1917
pub enum HostInternal {
@@ -228,81 +226,6 @@ impl<S: AsRef<str>> fmt::Display for Host<S> {
228226
}
229227
}
230228

231-
/// This mostly exists because coherence rules don’t allow us to implement
232-
/// `ToSocketAddrs for (Host<S>, u16)`.
233-
#[derive(Clone, Debug)]
234-
pub struct HostAndPort<S = String> {
235-
pub host: Host<S>,
236-
pub port: u16,
237-
}
238-
239-
impl<'a> HostAndPort<&'a str> {
240-
/// Return a copy of `self` that owns an allocated `String` but does not borrow an `&Url`.
241-
pub fn to_owned(&self) -> HostAndPort<String> {
242-
HostAndPort {
243-
host: self.host.to_owned(),
244-
port: self.port,
245-
}
246-
}
247-
}
248-
249-
impl<S: AsRef<str>> fmt::Display for HostAndPort<S> {
250-
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
251-
self.host.fmt(f)?;
252-
f.write_str(":")?;
253-
self.port.fmt(f)
254-
}
255-
}
256-
257-
impl<S: AsRef<str>> ToSocketAddrs for HostAndPort<S> {
258-
type Iter = SocketAddrs;
259-
260-
fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
261-
let port = self.port;
262-
match self.host {
263-
Host::Domain(ref domain) => Ok(SocketAddrs {
264-
// FIXME: use std::net::lookup_host when it’s stable.
265-
state: SocketAddrsState::Domain((domain.as_ref(), port).to_socket_addrs()?),
266-
}),
267-
Host::Ipv4(address) => Ok(SocketAddrs {
268-
state: SocketAddrsState::One(SocketAddr::V4(SocketAddrV4::new(address, port))),
269-
}),
270-
Host::Ipv6(address) => Ok(SocketAddrs {
271-
state: SocketAddrsState::One(SocketAddr::V6(SocketAddrV6::new(
272-
address, port, 0, 0,
273-
))),
274-
}),
275-
}
276-
}
277-
}
278-
279-
/// Socket addresses for an URL.
280-
#[derive(Debug)]
281-
pub struct SocketAddrs {
282-
state: SocketAddrsState,
283-
}
284-
285-
#[derive(Debug)]
286-
enum SocketAddrsState {
287-
Domain(vec::IntoIter<SocketAddr>),
288-
One(SocketAddr),
289-
Done,
290-
}
291-
292-
impl Iterator for SocketAddrs {
293-
type Item = SocketAddr;
294-
fn next(&mut self) -> Option<SocketAddr> {
295-
match self.state {
296-
SocketAddrsState::Domain(ref mut iter) => iter.next(),
297-
SocketAddrsState::One(s) => {
298-
self.state = SocketAddrsState::Done;
299-
Some(s)
300-
}
301-
SocketAddrsState::Done => None,
302-
}
303-
}
304-
}
305-
306229
fn write_ipv6(addr: &Ipv6Addr, f: &mut Formatter) -> fmt::Result {
307230
let segments = addr.segments();
308231
let (compress_start, compress_end) = longest_zero_sequence(&segments);

src/lib.rs

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,13 @@ use std::cmp;
128128
use std::error::Error;
129129
use std::fmt::{self, Debug, Formatter, Write};
130130
use std::hash;
131-
use std::io;
132131
use std::mem;
133-
use std::net::{IpAddr, ToSocketAddrs};
132+
use std::net::IpAddr;
134133
use std::ops::{Range, RangeFrom, RangeTo};
135134
use std::path::{Path, PathBuf};
136135
use std::str;
137136

138-
pub use host::{Host, HostAndPort, SocketAddrs};
137+
pub use host::Host;
139138
pub use origin::{OpaqueOrigin, Origin};
140139
pub use parser::{ParseError, SyntaxViolation};
141140
pub use path_segments::PathSegmentsMut;
@@ -963,51 +962,6 @@ impl Url {
963962
self.port.or_else(|| parser::default_port(self.scheme()))
964963
}
965964

966-
/// If the URL has a host, return something that implements `ToSocketAddrs`.
967-
///
968-
/// If the URL has no port number and the scheme’s default port number is not known
969-
/// (see `Url::port_or_known_default`),
970-
/// the closure is called to obtain a port number.
971-
/// Typically, this closure can match on the result `Url::scheme`
972-
/// to have per-scheme default port numbers,
973-
/// and panic for schemes it’s not prepared to handle.
974-
/// For example:
975-
///
976-
/// ```rust
977-
/// # use url::Url;
978-
/// # use std::net::TcpStream;
979-
/// # use std::io;
980-
/// fn connect(url: &Url) -> io::Result<TcpStream> {
981-
/// TcpStream::connect(url.with_default_port(default_port)?)
982-
/// }
983-
///
984-
/// fn default_port(url: &Url) -> Result<u16, ()> {
985-
/// match url.scheme() {
986-
/// "git" => Ok(9418),
987-
/// "git+ssh" => Ok(22),
988-
/// "git+https" => Ok(443),
989-
/// "git+http" => Ok(80),
990-
/// _ => Err(()),
991-
/// }
992-
/// }
993-
/// ```
994-
pub fn with_default_port<F>(&self, f: F) -> io::Result<HostAndPort<&str>>
995-
where
996-
F: FnOnce(&Url) -> Result<u16, ()>,
997-
{
998-
Ok(HostAndPort {
999-
host: self
1000-
.host()
1001-
.ok_or(())
1002-
.or_else(|()| io_error("URL has no host"))?,
1003-
port: self
1004-
.port_or_known_default()
1005-
.ok_or(())
1006-
.or_else(|()| f(self))
1007-
.or_else(|()| io_error("URL has no port number"))?,
1008-
})
1009-
}
1010-
1011965
/// Return the path for this URL, as a percent-encoded ASCII string.
1012966
/// For cannot-be-a-base URLs, this is an arbitrary string that doesn’t start with '/'.
1013967
/// For other URLs, this starts with a '/' slash
@@ -2204,15 +2158,6 @@ impl Url {
22042158
}
22052159
}
22062160

2207-
/// Return an error if `Url::host` or `Url::port_or_known_default` return `None`.
2208-
impl ToSocketAddrs for Url {
2209-
type Iter = SocketAddrs;
2210-
2211-
fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
2212-
self.with_default_port(|_| Err(()))?.to_socket_addrs()
2213-
}
2214-
}
2215-
22162161
/// Parse a string as an URL, without a base URL or encoding override.
22172162
impl str::FromStr for Url {
22182163
type Err = ParseError;
@@ -2519,10 +2464,6 @@ fn file_url_segments_to_pathbuf_windows(
25192464
Ok(path)
25202465
}
25212466

2522-
fn io_error<T>(reason: &str) -> io::Result<T> {
2523-
Err(io::Error::new(io::ErrorKind::InvalidData, reason))
2524-
}
2525-
25262467
/// Implementation detail of `Url::query_pairs_mut`. Typically not used directly.
25272468
#[derive(Debug)]
25282469
pub struct UrlQuery<'a> {

tests/unit.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::borrow::Cow;
1616
use std::cell::{Cell, RefCell};
1717
use std::net::{Ipv4Addr, Ipv6Addr};
1818
use std::path::{Path, PathBuf};
19-
use url::{form_urlencoded, Host, HostAndPort, Url};
19+
use url::{form_urlencoded, Host, Url};
2020

2121
#[test]
2222
fn size() {
@@ -329,42 +329,6 @@ fn form_urlencoded_custom_encoding_override() {
329329
assert_eq!(encoded, "FOO=BAR");
330330
}
331331

332-
#[test]
333-
fn host_and_port_display() {
334-
assert_eq!(
335-
format!(
336-
"{}",
337-
HostAndPort {
338-
host: Host::Domain("www.mozilla.org"),
339-
port: 80
340-
}
341-
),
342-
"www.mozilla.org:80"
343-
);
344-
assert_eq!(
345-
format!(
346-
"{}",
347-
HostAndPort::<String> {
348-
host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)),
349-
port: 65535
350-
}
351-
),
352-
"1.35.33.49:65535"
353-
);
354-
assert_eq!(
355-
format!(
356-
"{}",
357-
HostAndPort::<String> {
358-
host: Host::Ipv6(Ipv6Addr::new(
359-
0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
360-
)),
361-
port: 1337
362-
}
363-
),
364-
"[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
365-
)
366-
}
367-
368332
#[test]
369333
/// https://github.com/servo/rust-url/issues/61
370334
fn issue_61() {

0 commit comments

Comments
 (0)