@@ -115,24 +115,6 @@ struct Scheme(Hashable, EqualityComparable, Representable, Stringable, Writable)
115115 return self .value.upper()
116116
117117
118- fn parse_host_and_port (source : String, is_tls : Bool) raises -> (String, UInt16):
119- """ Parses the host and port from a given string.
120-
121- Args:
122- source: The host uri to parse.
123- is_tls: A boolean indicating whether the connection is secure.
124-
125- Returns:
126- A tuple containing the host and port.
127- """
128- if source.count(" :" ) != 1 :
129- var port : UInt16 = 443 if is_tls else 80
130- return source, port
131-
132- var result = source.split(" :" )
133- return result[0 ], UInt16(atol(result[1 ]))
134-
135-
136118@value
137119struct URI (Writable , Stringable , Representable ):
138120 var _original_path : String
@@ -193,6 +175,15 @@ struct URI(Writable, Stringable, Representable):
193175 else :
194176 host = str (host_and_port)
195177
178+ # Reads until either the start of the query string, or the end of the uri.
179+ var unquote_reader = reader.copy()
180+ var original_path_bytes = unquote_reader.read_until(Constant.QUESTION )
181+ var original_path : String
182+ if not original_path_bytes:
183+ original_path = " /"
184+ else :
185+ original_path = unquote(str (original_path_bytes), disallowed_escapes = List(str (" /" )))
186+
196187 # Parse the path
197188 var path : String = " /"
198189 var request_uri : String = " /"
@@ -201,7 +192,7 @@ struct URI(Writable, Stringable, Representable):
201192 var request_uri_reader = reader.copy()
202193 request_uri = str (request_uri_reader.read_bytes())
203194 # Read until the query string, or the end if there is none.
204- path = str (reader.read_until(Constant.QUESTION ))
195+ path = unquote( str (reader.read_until(Constant.QUESTION )), disallowed_escapes = List( str ( " / " ) ))
205196
206197 # Parse query
207198 var query : String = " "
@@ -223,7 +214,7 @@ struct URI(Writable, Stringable, Representable):
223214 queries[key] = unquote[expand_plus=True ](key_val[1 ])
224215
225216 return URI(
226- _original_path = path ,
217+ _original_path = original_path ,
227218 scheme = scheme,
228219 path = path,
229220 query_string = query,
0 commit comments