@@ -145,20 +145,7 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<
145
145
if path_and_query. starts_with ( "http://" ) || path_and_query. starts_with ( "https://" ) {
146
146
Ok ( Url :: parse ( path_and_query) ?)
147
147
} else if path_and_query. starts_with ( '/' ) {
148
- let mut url = Url :: parse ( & format ! ( "http://{}/" , host) ) ?;
149
- // path might start with `//`, so set the path explicitly using `set_path`
150
-
151
- let mut split = path_and_query. split ( "?" ) ;
152
- if let Some ( path) = split. next ( ) {
153
- url. set_path ( path) ;
154
- } else {
155
- return Err ( format_err ! ( "unexpected uri format" ) ) ;
156
- }
157
- if let Some ( query) = split. next ( ) {
158
- url. set_query ( Some ( query) ) ;
159
- }
160
-
161
- Ok ( url)
148
+ Ok ( Url :: parse ( & format ! ( "http://{}{}" , host, path_and_query) ) ?)
162
149
} else if req. method . unwrap ( ) . eq_ignore_ascii_case ( "connect" ) {
163
150
Ok ( Url :: parse ( & format ! ( "http://{}/" , path_and_query) ) ?)
164
151
} else {
@@ -244,6 +231,19 @@ mod tests {
244
231
} ,
245
232
)
246
233
}
234
+ #[ test]
235
+ fn url_for_triple_slash_path ( ) {
236
+ httparse_req (
237
+ "GET ///triple/slashes HTTP/1.1\r \n Host: server.example.com:443\r \n " ,
238
+ |req| {
239
+ let url = url_from_httparse_req ( & req) . unwrap ( ) ;
240
+ assert_eq ! (
241
+ url. as_str( ) ,
242
+ "http://server.example.com:443///triple/slashes"
243
+ ) ;
244
+ } ,
245
+ )
246
+ }
247
247
248
248
#[ test]
249
249
fn url_for_query ( ) {
@@ -255,4 +255,18 @@ mod tests {
255
255
} ,
256
256
)
257
257
}
258
+
259
+ #[ test]
260
+ fn url_for_anchor ( ) {
261
+ httparse_req (
262
+ "GET /foo?bar=1#anchor HTTP/1.1\r \n Host: server.example.com:443\r \n " ,
263
+ |req| {
264
+ let url = url_from_httparse_req ( & req) . unwrap ( ) ;
265
+ assert_eq ! (
266
+ url. as_str( ) ,
267
+ "http://server.example.com:443/foo?bar=1#anchor"
268
+ ) ;
269
+ } ,
270
+ )
271
+ }
258
272
}
0 commit comments