Skip to content

Commit 8cb53fb

Browse files
committed
Handle opening directory
1 parent 399d3da commit 8cb53fb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/handler/fs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ async fn file_response(path: &Path) -> http::Response<Body> {
120120
log::info!("Invalid file name: `{}`", path.display());
121121
return error::from_status(http::StatusCode::NOT_FOUND);
122122
}
123+
#[cfg(windows)]
124+
Err(err) if err.raw_os_error() == Some(5) && path.is_dir() => {
125+
log::info!("Path is a directory: `{}`", path.display());
126+
return error::from_status(http::StatusCode::NOT_FOUND);
127+
}
128+
#[cfg(unix)]
129+
Err(err) if err.raw_os_error() == Some(21) => {
130+
log::info!("Path is a directory: `{}`", path.display());
131+
return error::from_status(http::StatusCode::NOT_FOUND);
132+
}
123133
Err(err) => {
124134
log::error!("Error opening file: {}", err);
125135
return error::from_status(http::StatusCode::INTERNAL_SERVER_ERROR);

0 commit comments

Comments
 (0)