From 37b26e21e8ef323eea02f6a715a2030114c764ed Mon Sep 17 00:00:00 2001 From: M3rs Date: Sun, 22 Jan 2017 10:51:06 -0600 Subject: [PATCH] refactor(uri): Add default path for absolute-form Add default path ("/") for absolute-form, even if not included. This change assumes self.scheme().is_some() indicates that the Uri is in absolute-form. Issue: https://github.com/hyperium/hyper/issues/1022 --- src/uri.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/uri.rs b/src/uri.rs index a303f573..22c767f7 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -88,6 +88,9 @@ impl Uri { let end = self.source.len() - if query_len > 0 { query_len + 1 } else { 0 } - if fragment_len > 0 { fragment_len + 1 } else { 0 }; if index >= end { + if self.scheme().is_some() { + return "/" // absolute-form MUST have path + } "" } else { &self.source[index..end] @@ -317,7 +320,7 @@ test_parse! { "http://127.0.0.1:80", scheme = Some("http"), - authority = Some("127.0.0.1"), + authority = Some("127.0.0.1:80"), path = "/", query = None, fragment = None, @@ -328,7 +331,7 @@ test_parse! { "https://127.0.0.1:443", scheme = Some("https"), - authority = Some("127.0.0.1"), + authority = Some("127.0.0.1:443"), path = "/", query = None, fragment = None,