diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 2c3be20..0d2f34b 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -303,7 +303,7 @@ impl Uri { _ => {} } - if s[0] == b'/' && s[1] != b'/' { + if s[0] == b'/' { return Ok(Uri { scheme: Scheme::empty(), authority: Authority::empty(), @@ -827,10 +827,6 @@ fn parse_full(mut s: Bytes) -> Result { // Parse the scheme let scheme = match Scheme2::parse(&s[..]).map_err(InvalidUriBytes)? { Scheme2::None => Scheme2::None, - Scheme2::Relative =>{ - let _ = s.split_to(2); - Scheme2::Relative - } Scheme2::Standard(p) => { // TODO: use truncate let _ = s.split_to(p.len() + 3); @@ -924,26 +920,24 @@ impl PartialEq for Uri { let mut absolute = false; if let Some(scheme) = self.scheme_part() { - - let delimiter_width = if let Scheme2::Relative = scheme.inner { 2 } else { 3 }; - - let scheme_bytes = scheme.as_str().as_bytes(); + let scheme = scheme.as_str().as_bytes(); absolute = true; - if other.len() < scheme_bytes.len() + delimiter_width { + if other.len() < scheme.len() + 3 { return false; } - if !scheme_bytes.eq_ignore_ascii_case(&other[..scheme_bytes.len()]) { - return false; - } - other = &other[scheme_bytes.len()..]; - - if &other[..delimiter_width] != &(b"://"[3-delimiter_width..]) { + if !scheme.eq_ignore_ascii_case(&other[..scheme.len()]) { return false; } - other = &other[delimiter_width..]; + other = &other[scheme.len()..]; + + if &other[..3] != b"://" { + return false; + } + + other = &other[3..]; } if let Some(auth) = self.authority_part() { @@ -1034,10 +1028,7 @@ 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() { - match scheme.inner{ - Scheme2::Relative => write!(f, "//")?, - _ => write!(f, "{}://", scheme)? - } + write!(f, "{}://", scheme)?; } if let Some(authority) = self.authority_part() { diff --git a/src/uri/scheme.rs b/src/uri/scheme.rs index 3b66184..78e59fc 100644 --- a/src/uri/scheme.rs +++ b/src/uri/scheme.rs @@ -20,7 +20,6 @@ pub struct Scheme { #[derive(Clone, Debug)] pub(super) enum Scheme2> { None, - Relative, Standard(Protocol), Other(T), } @@ -68,7 +67,6 @@ impl Scheme { match Scheme2::parse_exact(&s[..]).map_err(InvalidUriBytes)? { None => Err(ErrorKind::InvalidScheme.into()), - Relative => Ok(Relative.into()), Standard(p) => Ok(Standard(p).into()), Other(_) => { let b = unsafe { ByteStr::from_utf8_unchecked(s) }; @@ -100,7 +98,6 @@ impl Scheme { match self.inner { Standard(Http) => "http", Standard(Https) => "https", - Relative => "", Other(ref v) => &v[..], None => unreachable!(), } @@ -129,7 +126,6 @@ impl<'a> HttpTryFrom<&'a [u8]> for Scheme { match Scheme2::parse_exact(s)? { None => Err(ErrorKind::InvalidScheme.into()), - Relative => Ok(Relative.into()), Standard(p) => Ok(Standard(p).into()), Other(_) => { // Unsafe: parse_exact already checks for a strict subset of UTF-8 @@ -165,7 +161,6 @@ impl From for Bytes { match src.inner { None => Bytes::new(), - Relative => Bytes::new(), Standard(Http) => Bytes::from_static(b"http"), Standard(Https) => Bytes::from_static(b"https"), Other(v) => (*v).into(), @@ -198,7 +193,6 @@ impl PartialEq for Scheme { use self::Scheme2::*; match (&self.inner, &other.inner) { - (&Relative,&Relative) => true, (&Standard(Http), &Standard(Http)) => true, (&Standard(Https), &Standard(Https)) => true, (&Other(ref a), &Other(ref b)) => a.eq_ignore_ascii_case(b), @@ -237,7 +231,6 @@ impl Hash for Scheme { fn hash(&self, state: &mut H) where H: Hasher { match self.inner { Scheme2::None => (), - Scheme2::Relative => state.write_u8(3), Scheme2::Standard(Protocol::Http) => state.write_u8(1), Scheme2::Standard(Protocol::Https) => state.write_u8(2), Scheme2::Other(ref other) => { @@ -300,7 +293,6 @@ impl Scheme2 { match s { b"http" => Ok(Protocol::Http.into()), b"https" => Ok(Protocol::Https.into()), - b"//" => Ok(Scheme2::Relative), _ => { if s.len() > MAX_SCHEME_LEN { return Err(ErrorKind::SchemeTooLong.into()); @@ -370,10 +362,6 @@ impl Scheme2 { } } - if s.starts_with(b"//") { - return Ok(Scheme2::Relative.into()) - } - Ok(Scheme2::None) } } diff --git a/src/uri/tests.rs b/src/uri/tests.rs index 2e03cd2..71f9351 100644 --- a/src/uri/tests.rs +++ b/src/uri/tests.rs @@ -54,18 +54,6 @@ macro_rules! test_parse { ); } -test_parse! { - test_uri_parse_protocol_relative, - "//some/path/here", - [], - - scheme_part = part!("//"), - authority_part = part!("some"), - path = "/path/here", -} - - - test_parse! { test_uri_parse_path_and_query, "/some/path/here?and=then&hello#and-bye",