Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tower-http/src/services/fs/serve_dir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ impl<F> ServeDir<F> {
inner: future::call_fallback(fallback, req),
};
}
} else {
return ResponseFuture::method_not_allowed();
}

return ResponseFuture::method_not_allowed();
}

// `ServeDir` doesn't care about the request body but the fallback might. So move out the
Expand Down
15 changes: 15 additions & 0 deletions tower-http/src/services/fs/serve_dir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,21 @@ async fn calling_fallback_on_not_allowed() {
assert_eq!(body, "from fallback /doesnt-exist");
}

#[tokio::test]
async fn method_not_allowed_without_fallback() {
let svc = ServeDir::new("..").call_fallback_on_method_not_allowed(true);

let req = Request::builder()
.method(Method::POST)
.uri("/README.md")
.body(Body::empty())
.unwrap();
let res = svc.oneshot(req).await.unwrap();

assert_eq!(res.status(), StatusCode::METHOD_NOT_ALLOWED);
assert_eq!(res.headers()[ALLOW], "GET,HEAD");
}

#[tokio::test]
async fn with_fallback_svc_and_not_append_index_html_on_directories() {
async fn fallback<B>(req: Request<B>) -> Result<Response<Body>, Infallible> {
Expand Down
Loading