diff --git a/src/lib.rs b/src/lib.rs index 874cbbbb..a5f23d28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,10 +148,11 @@ //! //! ``` //! use http::Uri; +//! use http::uri::Scheme; //! //! let uri = "https://www.rust-lang.org/index.html".parse::().unwrap(); //! -//! assert_eq!(uri.scheme_str(), Some("https")); +//! assert_eq!(uri.scheme(), Some(&Scheme::HTTPS)); //! assert_eq!(uri.host(), Some("www.rust-lang.org")); //! assert_eq!(uri.path(), "/index.html"); //! assert_eq!(uri.query(), None); diff --git a/src/uri/authority.rs b/src/uri/authority.rs index 0564f2b5..3574fb73 100644 --- a/src/uri/authority.rs +++ b/src/uri/authority.rs @@ -205,12 +205,6 @@ impl Authority { host(self.as_str()) } - #[deprecated(since="0.1.14", note="use `port_part` or `port_u16` instead")] - #[doc(hidden)] - pub fn port(&self) -> Option { - self.port_u16() - } - /// Get the port part of this `Authority`. /// /// The port subcomponent of authority is designated by an optional port @@ -233,7 +227,7 @@ impl Authority { /// # use http::uri::Authority; /// let authority: Authority = "example.org:80".parse().unwrap(); /// - /// let port = authority.port_part().unwrap(); + /// let port = authority.port().unwrap(); /// assert_eq!(port.as_u16(), 80); /// assert_eq!(port.as_str(), "80"); /// ``` @@ -244,9 +238,9 @@ impl Authority { /// # use http::uri::Authority; /// let authority: Authority = "example.org".parse().unwrap(); /// - /// assert!(authority.port_part().is_none()); + /// assert!(authority.port().is_none()); /// ``` - pub fn port_part(&self) -> Option> { + pub fn port(&self) -> Option> { let bytes = self.as_str(); bytes .rfind(":") @@ -264,7 +258,7 @@ impl Authority { /// assert_eq!(authority.port_u16(), Some(80)); /// ``` pub fn port_u16(&self) -> Option { - self.port_part().and_then(|p| Some(p.as_u16())) + self.port().and_then(|p| Some(p.as_u16())) } /// Return a str representation of the authority diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 0d2f34b8..4549a4eb 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -17,7 +17,7 @@ //! assert_eq!(uri.host(), None); //! //! let uri = "https://www.rust-lang.org/install.html".parse::().unwrap(); -//! assert_eq!(uri.scheme_part().map(|s| s.as_str()), Some("https")); +//! assert_eq!(uri.scheme_str(), Some("https")); //! assert_eq!(uri.host(), Some("www.rust-lang.org")); //! assert_eq!(uri.path(), "/install.html"); //! ``` @@ -28,9 +28,6 @@ use byte_str::ByteStr; use bytes::Bytes; use std::{fmt, u8, u16}; -// Deprecated in 1.26, needed until our minimum version is >=1.23. -#[allow(unused, deprecated)] -use std::ascii::AsciiExt; use std::hash::{Hash, Hasher}; use std::str::{self, FromStr}; use std::error::Error; @@ -91,7 +88,7 @@ mod tests; /// assert_eq!(uri.host(), None); /// /// let uri = "https://www.rust-lang.org/install.html".parse::().unwrap(); -/// assert_eq!(uri.scheme_part().map(|s| s.as_str()), Some("https")); +/// assert_eq!(uri.scheme_str(), Some("https")); /// assert_eq!(uri.host(), Some("www.rust-lang.org")); /// assert_eq!(uri.path(), "/install.html"); /// ``` @@ -441,7 +438,7 @@ impl Uri { /// /// let uri: Uri = "http://example.org/hello/world".parse().unwrap(); /// - /// assert_eq!(uri.scheme_part(), Some(&Scheme::HTTP)); + /// assert_eq!(uri.scheme(), Some(&Scheme::HTTP)); /// ``` /// /// @@ -451,10 +448,10 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "/hello/world".parse().unwrap(); /// - /// assert!(uri.scheme_part().is_none()); + /// assert!(uri.scheme().is_none()); /// ``` #[inline] - pub fn scheme_part(&self) -> Option<&Scheme> { + pub fn scheme(&self) -> Option<&Scheme> { if self.scheme.inner.is_none() { None } else { @@ -462,13 +459,6 @@ impl Uri { } } - #[deprecated(since = "0.1.2", note = "use scheme_part or scheme_str instead")] - #[doc(hidden)] - #[inline] - pub fn scheme(&self) -> Option<&str> { - self.scheme_str() - } - /// Get the scheme of this `Uri` as a `&str`. /// /// # Example @@ -515,7 +505,7 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "http://example.org:80/hello/world".parse().unwrap(); /// - /// assert_eq!(uri.authority_part().map(|a| a.as_str()), Some("example.org:80")); + /// assert_eq!(uri.authority().map(|a| a.as_str()), Some("example.org:80")); /// ``` /// /// @@ -525,10 +515,10 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "/hello/world".parse().unwrap(); /// - /// assert!(uri.authority_part().is_none()); + /// assert!(uri.authority().is_none()); /// ``` #[inline] - pub fn authority_part(&self) -> Option<&Authority> { + pub fn authority(&self) -> Option<&Authority> { if self.authority.data.is_empty() { None } else { @@ -536,17 +526,6 @@ impl Uri { } } - #[deprecated(since = "0.1.1", note = "use authority_part instead")] - #[doc(hidden)] - #[inline] - pub fn authority(&self) -> Option<&str> { - if self.authority.data.is_empty() { - None - } else { - Some(self.authority.as_str()) - } - } - /// Get the host of this `Uri`. /// /// The host subcomponent of authority is identified by an IP literal @@ -582,13 +561,7 @@ impl Uri { /// ``` #[inline] pub fn host(&self) -> Option<&str> { - self.authority_part().map(|a| a.host()) - } - - #[deprecated(since="0.1.14", note="use `port_part` or `port_u16` instead")] - #[doc(hidden)] - pub fn port(&self) -> Option { - self.port_u16() + self.authority().map(|a| a.host()) } /// Get the port part of this `Uri`. @@ -613,7 +586,7 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "http://example.org:80/hello/world".parse().unwrap(); /// - /// let port = uri.port_part().unwrap(); + /// let port = uri.port().unwrap(); /// assert_eq!(port.as_u16(), 80); /// ``` /// @@ -623,7 +596,7 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "http://example.org/hello/world".parse().unwrap(); /// - /// assert!(uri.port_part().is_none()); + /// assert!(uri.port().is_none()); /// ``` /// /// Relative URI @@ -632,11 +605,11 @@ impl Uri { /// # use http::Uri; /// let uri: Uri = "/hello/world".parse().unwrap(); /// - /// assert!(uri.port_part().is_none()); + /// assert!(uri.port().is_none()); /// ``` - pub fn port_part(&self) -> Option> { - self.authority_part() - .and_then(|a| a.port_part()) + pub fn port(&self) -> Option> { + self.authority() + .and_then(|a| a.port()) } /// Get the port of this `Uri` as a `u16`. @@ -651,7 +624,7 @@ impl Uri { /// assert_eq!(uri.port_u16(), Some(80)); /// ``` pub fn port_u16(&self) -> Option { - self.port_part().and_then(|p| Some(p.as_u16())) + self.port().and_then(|p| Some(p.as_u16())) } /// Get the query string of this `Uri`, starting after the `?`. @@ -776,7 +749,7 @@ impl<'a> HttpTryFrom<&'a Uri> for Uri { /// /// assert_eq!(uri.path(), "/foo"); /// -/// assert!(uri.scheme_part().is_none()); +/// assert!(uri.scheme().is_none()); /// assert!(uri.authority().is_none()); /// ``` /// @@ -791,7 +764,7 @@ impl<'a> HttpTryFrom<&'a Uri> for Uri { /// /// let uri = Uri::from_parts(parts).unwrap(); /// -/// assert_eq!(uri.scheme_part().unwrap().as_str(), "http"); +/// assert_eq!(uri.scheme().unwrap().as_str(), "http"); /// assert_eq!(uri.authority().unwrap(), "foo.com"); /// assert_eq!(uri.path(), "/foo"); /// ``` @@ -894,11 +867,11 @@ impl FromStr for Uri { impl PartialEq for Uri { fn eq(&self, other: &Uri) -> bool { - if self.scheme_part() != other.scheme_part() { + if self.scheme() != other.scheme() { return false; } - if self.authority_part() != other.authority_part() { + if self.authority() != other.authority() { return false; } @@ -919,7 +892,7 @@ impl PartialEq for Uri { let mut other = other.as_bytes(); let mut absolute = false; - if let Some(scheme) = self.scheme_part() { + if let Some(scheme) = self.scheme() { let scheme = scheme.as_str().as_bytes(); absolute = true; @@ -940,7 +913,7 @@ impl PartialEq for Uri { other = &other[3..]; } - if let Some(auth) = self.authority_part() { + if let Some(auth) = self.authority() { let len = auth.data.len(); absolute = true; @@ -1027,11 +1000,11 @@ impl Default for Uri { impl fmt::Display for Uri { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if let Some(scheme) = self.scheme_part() { + if let Some(scheme) = self.scheme() { write!(f, "{}://", scheme)?; } - if let Some(authority) = self.authority_part() { + if let Some(authority) = self.authority() { write!(f, "{}", authority)?; } @@ -1124,7 +1097,7 @@ impl Hash for Uri { state.write_u8(0xff); } - if let Some(auth) = self.authority_part() { + if let Some(auth) = self.authority() { auth.hash(state); } diff --git a/src/uri/path.rs b/src/uri/path.rs index 2cafbf89..64001eb8 100644 --- a/src/uri/path.rs +++ b/src/uri/path.rs @@ -69,10 +69,10 @@ impl PathAndQuery { // percent-encoded in the path. If it should have been // percent-encoded, then error. 0x21 | - 0x24...0x3B | + 0x24..=0x3B | 0x3D | - 0x40...0x5F | - 0x61...0x7A | + 0x40..=0x5F | + 0x61..=0x7A | 0x7C | 0x7E => {}, @@ -94,9 +94,9 @@ impl PathAndQuery { // // Allowed: 0x21 / 0x24 - 0x3B / 0x3D / 0x3F - 0x7E 0x21 | - 0x24...0x3B | + 0x24..=0x3B | 0x3D | - 0x3F...0x7E => {}, + 0x3F..=0x7E => {}, b'#' => { fragment = Some(i); diff --git a/src/uri/port.rs b/src/uri/port.rs index d3177a7a..01077ac9 100644 --- a/src/uri/port.rs +++ b/src/uri/port.rs @@ -19,7 +19,7 @@ impl Port { /// # use http::uri::Authority; /// let authority: Authority = "example.org:80".parse().unwrap(); /// - /// let port = authority.port_part().unwrap(); + /// let port = authority.port().unwrap(); /// assert_eq!(port.as_u16(), 80); /// ``` pub fn as_u16(&self) -> u16 { @@ -57,7 +57,7 @@ where /// # use http::uri::Authority; /// let authority: Authority = "example.org:80".parse().unwrap(); /// - /// let port = authority.port_part().unwrap(); + /// let port = authority.port().unwrap(); /// assert_eq!(port.as_str(), "80"); /// ``` pub fn as_str(&self) -> &str { diff --git a/src/uri/tests.rs b/src/uri/tests.rs index 9a9ccc80..d6943829 100644 --- a/src/uri/tests.rs +++ b/src/uri/tests.rs @@ -59,8 +59,8 @@ test_parse! { "/some/path/here?and=then&hello#and-bye", [], - scheme_part = None, - authority_part = None, + scheme = None, + authority = None, path = "/some/path/here", query = Some("and=then&hello"), host = None, @@ -71,12 +71,12 @@ test_parse! { "http://127.0.0.1:61761/chunks", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1:61761"), + scheme = part!("http"), + authority = part!("127.0.0.1:61761"), path = "/chunks", query = None, host = Some("127.0.0.1"), - port_part = Port::from_str("61761").ok(), + port = Port::from_str("61761").ok(), } test_parse! { @@ -84,12 +84,12 @@ test_parse! { "https://127.0.0.1:61761", ["https://127.0.0.1:61761/"], - scheme_part = part!("https"), - authority_part = part!("127.0.0.1:61761"), + scheme = part!("https"), + authority = part!("127.0.0.1:61761"), path = "/", query = None, host = Some("127.0.0.1"), - port_part = Port::from_str("61761").ok(), + port = Port::from_str("61761").ok(), } test_parse! { @@ -97,8 +97,8 @@ test_parse! { "*", [], - scheme_part = None, - authority_part = None, + scheme = None, + authority = None, path = "*", query = None, host = None, @@ -109,11 +109,11 @@ test_parse! { "localhost", ["LOCALHOST", "LocaLHOSt"], - scheme_part = None, - authority_part = part!("localhost"), + scheme = None, + authority = part!("localhost"), path = "", query = None, - port_part = None, + port = None, host = Some("localhost"), } @@ -122,11 +122,11 @@ test_parse! { "S", [], - scheme_part = None, - authority_part = part!("S"), + scheme = None, + authority = part!("S"), path = "", query = None, - port_part = None, + port = None, host = Some("S"), } @@ -135,12 +135,12 @@ test_parse! { "localhost:3000", ["localhosT:3000"], - scheme_part = None, - authority_part = part!("localhost:3000"), + scheme = None, + authority = part!("localhost:3000"), path = "", query = None, host = Some("localhost"), - port_part = Port::from_str("3000").ok(), + port = Port::from_str("3000").ok(), } @@ -149,12 +149,12 @@ test_parse! { "http://127.0.0.1:80", ["http://127.0.0.1:80/"], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1:80"), + scheme = part!("http"), + authority = part!("127.0.0.1:80"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = Port::from_str("80").ok(), + port = Port::from_str("80").ok(), } test_parse! { @@ -162,12 +162,12 @@ test_parse! { "https://127.0.0.1:443", ["https://127.0.0.1:443/"], - scheme_part = part!("https"), - authority_part = part!("127.0.0.1:443"), + scheme = part!("https"), + authority = part!("127.0.0.1:443"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = Port::from_str("443").ok(), + port = Port::from_str("443").ok(), } test_parse! { @@ -175,12 +175,12 @@ test_parse! { "http://127.0.0.1/#?", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1"), + scheme = part!("http"), + authority = part!("127.0.0.1"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -188,11 +188,11 @@ test_parse! { "http://127.0.0.1/path?", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1"), + scheme = part!("http"), + authority = part!("127.0.0.1"), path = "/path", query = Some(""), - port_part = None, + port = None, } test_parse! { @@ -200,11 +200,11 @@ test_parse! { "http://127.0.0.1?foo=bar", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1"), + scheme = part!("http"), + authority = part!("127.0.0.1"), path = "/", query = Some("foo=bar"), - port_part = None, + port = None, } test_parse! { @@ -212,11 +212,11 @@ test_parse! { "http://127.0.0.1#foo/bar", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1"), + scheme = part!("http"), + authority = part!("127.0.0.1"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -224,11 +224,11 @@ test_parse! { "http://127.0.0.1#foo?bar", [], - scheme_part = part!("http"), - authority_part = part!("127.0.0.1"), + scheme = part!("http"), + authority = part!("127.0.0.1"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -236,11 +236,11 @@ test_parse! { "thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost", [], - scheme_part = None, - authority_part = part!("thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost"), + scheme = None, + authority = part!("thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost"), path = "", query = None, - port_part = None, + port = None, } test_parse! { @@ -248,11 +248,11 @@ test_parse! { "thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost:1234", [], - scheme_part = None, - authority_part = part!("thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost:1234"), + scheme = None, + authority = part!("thequickbrownfoxjumpedoverthelazydogtofindthelargedangerousdragon.localhost:1234"), path = "", query = None, - port_part = Port::from_str("1234").ok(), + port = Port::from_str("1234").ok(), } test_parse! { @@ -260,12 +260,12 @@ test_parse! { "http://a:b@127.0.0.1:1234/", [], - scheme_part = part!("http"), - authority_part = part!("a:b@127.0.0.1:1234"), + scheme = part!("http"), + authority = part!("a:b@127.0.0.1:1234"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = Port::from_str("1234").ok(), + port = Port::from_str("1234").ok(), } test_parse! { @@ -273,12 +273,12 @@ test_parse! { "http://a:b@127.0.0.1/", [], - scheme_part = part!("http"), - authority_part = part!("a:b@127.0.0.1"), + scheme = part!("http"), + authority = part!("a:b@127.0.0.1"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -286,12 +286,12 @@ test_parse! { "http://a@127.0.0.1/", [], - scheme_part = part!("http"), - authority_part = part!("a@127.0.0.1"), + scheme = part!("http"), + authority = part!("a@127.0.0.1"), host = Some("127.0.0.1"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -299,12 +299,12 @@ test_parse! { "user@localhost:3000", [], - scheme_part = None, - authority_part = part!("user@localhost:3000"), + scheme = None, + authority = part!("user@localhost:3000"), path = "", query = None, host = Some("localhost"), - port_part = Port::from_str("3000").ok(), + port = Port::from_str("3000").ok(), } test_parse! { @@ -312,12 +312,12 @@ test_parse! { "user:pass@localhost:3000", [], - scheme_part = None, - authority_part = part!("user:pass@localhost:3000"), + scheme = None, + authority = part!("user:pass@localhost:3000"), path = "", query = None, host = Some("localhost"), - port_part = Port::from_str("3000").ok(), + port = Port::from_str("3000").ok(), } test_parse! { @@ -325,12 +325,12 @@ test_parse! { "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/", [], - scheme_part = part!("http"), - authority_part = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"), + scheme = part!("http"), + authority = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"), host = Some("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -338,12 +338,12 @@ test_parse! { "http://[::1]/", [], - scheme_part = part!("http"), - authority_part = part!("[::1]"), + scheme = part!("http"), + authority = part!("[::1]"), host = Some("[::1]"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -351,12 +351,12 @@ test_parse! { "http://[::]/", [], - scheme_part = part!("http"), - authority_part = part!("[::]"), + scheme = part!("http"), + authority = part!("[::]"), host = Some("[::]"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -364,12 +364,12 @@ test_parse! { "http://[2001:db8::2:1]/", [], - scheme_part = part!("http"), - authority_part = part!("[2001:db8::2:1]"), + scheme = part!("http"), + authority = part!("[2001:db8::2:1]"), host = Some("[2001:db8::2:1]"), path = "/", query = None, - port_part = None, + port = None, } test_parse! { @@ -377,12 +377,12 @@ test_parse! { "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8008/", [], - scheme_part = part!("http"), - authority_part = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8008"), + scheme = part!("http"), + authority = part!("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8008"), host = Some("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"), path = "/", query = None, - port_part = Port::from_str("8008").ok(), + port = Port::from_str("8008").ok(), } test_parse! { @@ -390,12 +390,12 @@ test_parse! { "/echo/abcdefgh_i-j%20/abcdefg_i-j%20478", [], - scheme_part = None, - authority_part = None, + scheme = None, + authority = None, host = None, path = "/echo/abcdefgh_i-j%20/abcdefg_i-j%20478", query = None, - port_part = None, + port = None, } test_parse! {