1
1
mod directory_entry;
2
2
mod file;
3
3
mod http_utils;
4
+ mod query_params;
4
5
mod scoped_file_system;
5
6
6
7
pub use file:: { File , FILE_BUFFER_SIZE } ;
@@ -59,13 +60,17 @@ impl<'a> FileServer {
59
60
Arc :: new ( handlebars)
60
61
}
61
62
62
- /// Retrieves the path from the URI and removes the query params
63
- fn sanitize_path ( req_uri : & str ) -> Result < PathBuf > {
63
+ fn parse_path ( req_uri : & str ) -> Result < PathBuf > {
64
64
let uri = Uri :: from_str ( req_uri) ?;
65
65
let uri_parts = uri. into_parts ( ) ;
66
66
67
67
if let Some ( path_and_query) = uri_parts. path_and_query {
68
68
let path = path_and_query. path ( ) ;
69
+ let _queries = if let Some ( query_str) = path_and_query. query ( ) {
70
+ Some ( query_params:: QueryParams :: from_str ( query_str) ?)
71
+ } else {
72
+ None
73
+ } ;
69
74
70
75
return Ok ( decode_uri ( path) ) ;
71
76
}
@@ -83,8 +88,8 @@ impl<'a> FileServer {
83
88
///
84
89
/// If the HTTP Request URI points to `/` (root), the default behavior
85
90
/// would be to respond with `Not Found` but in order to provide `root_dir`
86
- /// indexing, the request is handled and renders `root_dir` directory listing
87
- /// instead.
91
+ /// indexing, the request is handled and renders `root_dir` directory
92
+ /// listing instead.
88
93
///
89
94
/// If the HTTP Request doesn't match any file relative to `root_dir` then
90
95
/// responds with 'Not Found'
@@ -100,7 +105,7 @@ impl<'a> FileServer {
100
105
pub async fn resolve ( & self , req_path : String ) -> Result < Response < Body > > {
101
106
use std:: io:: ErrorKind ;
102
107
103
- let path = FileServer :: sanitize_path ( req_path. as_str ( ) ) ?;
108
+ let path = FileServer :: parse_path ( req_path. as_str ( ) ) ?;
104
109
105
110
match self . scoped_file_system . resolve ( path) . await {
106
111
Ok ( entry) => match entry {
@@ -280,7 +285,7 @@ mod tests {
280
285
}
281
286
282
287
#[ test]
283
- fn sanitize_req_uri_path ( ) {
288
+ fn parse_req_uri_path ( ) {
284
289
let have = vec ! [
285
290
"/index.html" ,
286
291
"/index.html?foo=1234" ,
@@ -296,7 +301,7 @@ mod tests {
296
301
] ;
297
302
298
303
for ( idx, req_uri) in have. iter ( ) . enumerate ( ) {
299
- let sanitized_path = FileServer :: sanitize_path ( req_uri) . unwrap ( ) ;
304
+ let sanitized_path = FileServer :: parse_path ( req_uri) . unwrap ( ) ;
300
305
let wanted_path = PathBuf :: from_str ( want[ idx] ) . unwrap ( ) ;
301
306
302
307
assert_eq ! ( sanitized_path, wanted_path) ;
0 commit comments