✨ Clean url with suffix
				
					
				
			This commit is contained in:
		| @@ -6,4 +6,4 @@ hosts = ["localhost"] | |||||||
| paths = ["/"] | paths = ["/"] | ||||||
| [[locations.destinations]] | [[locations.destinations]] | ||||||
| id = "static" | id = "static" | ||||||
| uri = "files://regions/index.html" | uri = "files://regions?index=index.html" | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								regions/subfolder/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								regions/subfolder/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | <!doctype html> | ||||||
|  | <html> | ||||||
|  |   <head> | ||||||
|  |     <meta charset="utf-8" /> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||||||
|  |     <title>Hello, World!</title> | ||||||
|  |   </head> | ||||||
|  |   <body> | ||||||
|  |     <p>Hello, there!</p> | ||||||
|  |     <p> | ||||||
|  |       Here's the roadsign benchmarking test data! And you are in the subfolder | ||||||
|  |       now! | ||||||
|  |     </p> | ||||||
|  |   </body> | ||||||
|  | </html> | ||||||
| @@ -98,20 +98,23 @@ impl Destination { | |||||||
|                         .get("utf8") |                         .get("utf8") | ||||||
|                         .and_then(|val| val.as_bool()) |                         .and_then(|val| val.as_bool()) | ||||||
|                         .unwrap_or(false), |                         .unwrap_or(false), | ||||||
|                     with_slash: queries |  | ||||||
|                         .get("slash") |  | ||||||
|                         .and_then(|val| val.as_bool()) |  | ||||||
|                         .unwrap_or(false), |  | ||||||
|                     browse: queries |                     browse: queries | ||||||
|                         .get("browse") |                         .get("browse") | ||||||
|                         .and_then(|val| val.as_bool()) |                         .and_then(|val| val.as_bool()) | ||||||
|                         .unwrap_or(false), |                         .unwrap_or(false), | ||||||
|  |                     with_slash: queries | ||||||
|  |                         .get("slash") | ||||||
|  |                         .and_then(|val| val.as_bool()) | ||||||
|  |                         .unwrap_or(false), | ||||||
|                     index: queries |                     index: queries | ||||||
|                         .get("index") |                         .get("index") | ||||||
|                         .and_then(|val| val.as_str().map(str::to_string)), |                         .and_then(|val| val.as_str().map(str::to_string)), | ||||||
|                     fallback: queries |                     fallback: queries | ||||||
|                         .get("fallback") |                         .get("fallback") | ||||||
|                         .and_then(|val| val.as_str().map(str::to_string)), |                         .and_then(|val| val.as_str().map(str::to_string)), | ||||||
|  |                     suffix: queries | ||||||
|  |                         .get("suffix") | ||||||
|  |                         .and_then(|val| val.as_str().map(str::to_string)), | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
|             _ => Err(()), |             _ => Err(()), | ||||||
|   | |||||||
| @@ -20,7 +20,9 @@ pub fn scan_regions(basepath: String) -> io::Result<(Vec<config::Region>, u32)> | |||||||
| } | } | ||||||
|  |  | ||||||
| pub fn load_region(file: DirEntry) -> Result<config::Region, String> { | pub fn load_region(file: DirEntry) -> Result<config::Region, String> { | ||||||
|     if file.path().extension().and_then(OsStr::to_str).unwrap() != "toml" { |     if file.metadata().map(|val| val.is_dir()).unwrap() | ||||||
|  |         || file.path().extension().and_then(OsStr::to_str).unwrap() != "toml" | ||||||
|  |     { | ||||||
|         return Err("File entry wasn't toml file".to_string()); |         return Err("File entry wasn't toml file".to_string()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -97,10 +97,11 @@ pub async fn respond_hypertext( | |||||||
| pub struct StaticResponderConfig { | pub struct StaticResponderConfig { | ||||||
|     pub uri: String, |     pub uri: String, | ||||||
|     pub utf8: bool, |     pub utf8: bool, | ||||||
|     pub with_slash: bool, |  | ||||||
|     pub browse: bool, |     pub browse: bool, | ||||||
|  |     pub with_slash: bool, | ||||||
|     pub index: Option<String>, |     pub index: Option<String>, | ||||||
|     pub fallback: Option<String>, |     pub fallback: Option<String>, | ||||||
|  |     pub suffix: Option<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| pub async fn respond_static( | pub async fn respond_static( | ||||||
| @@ -142,6 +143,22 @@ pub async fn respond_static( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     if !file_path.exists() { |     if !file_path.exists() { | ||||||
|  |         if let Some(suffix) = cfg.suffix { | ||||||
|  |             let file_name = file_path | ||||||
|  |                 .file_name() | ||||||
|  |                 .and_then(OsStr::to_str) | ||||||
|  |                 .unwrap() | ||||||
|  |                 .to_string(); | ||||||
|  |             file_path.pop(); | ||||||
|  |             file_path.push((file_name + &suffix).as_str()); | ||||||
|  |             if file_path.is_file() { | ||||||
|  |                 return Ok(StaticFileRequest::from_request_without_body(req) | ||||||
|  |                     .await? | ||||||
|  |                     .create_response(&file_path, cfg.utf8)? | ||||||
|  |                     .into_response()); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if let Some(file) = cfg.fallback { |         if let Some(file) = cfg.fallback { | ||||||
|             let fallback_path = base_path.join(file); |             let fallback_path = base_path.join(file); | ||||||
|             if fallback_path.is_file() { |             if fallback_path.is_file() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user