diff --git a/src/server.rs b/src/server.rs index 77deb8d..595721f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -270,8 +270,11 @@ impl Server { } } "MKCOL" => { - if !allow_upload || !is_miss { + if !allow_upload { status_forbid(&mut res); + } else if !is_miss { + *res.status_mut() = StatusCode::METHOD_NOT_ALLOWED; + *res.body_mut() = Body::from("Already exists"); } else { self.handle_mkcol(path, &mut res).await?; } diff --git a/tests/webdav.rs b/tests/webdav.rs index cedfad5..04b4ae0 100644 --- a/tests/webdav.rs +++ b/tests/webdav.rs @@ -93,6 +93,13 @@ fn mkcol_not_allow_upload(server: TestServer) -> Result<(), Error> { Ok(()) } +#[rstest] +fn mkcol_already_exists(#[with(&["-A"])] server: TestServer) -> Result<(), Error> { + let resp = fetch!(b"MKCOL", format!("{}dira", server.url())).send()?; + assert_eq!(resp.status(), 405); + Ok(()) +} + #[rstest] fn copy_file(#[with(&["-A"])] server: TestServer) -> Result<(), Error> { let new_url = format!("{}test2.html", server.url());