fix: add error handling for webdav mkcol according to RFC 4918 (#5581)

* feat: add error handling for mkcol method in webdav.go

* feat: update rfc reference

* fix: fix issue with uncorrect error handling
This commit is contained in:
Kuingsmile 2023-11-27 02:53:52 -08:00 committed by GitHub
parent 54e75d7287
commit f4dcf4599c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -382,6 +382,21 @@ func (h *Handler) handleMkcol(w http.ResponseWriter, r *http.Request) (status in
if r.ContentLength > 0 {
return http.StatusUnsupportedMediaType, nil
}
// RFC 4918 9.3.1
//405 (Method Not Allowed) - MKCOL can only be executed on an unmapped URL
if _, err := fs.Get(ctx, reqPath, &fs.GetArgs{}); err == nil {
return http.StatusMethodNotAllowed, err
}
// RFC 4918 9.3.1
// 409 (Conflict) The server MUST NOT create those intermediate collections automatically.
reqDir := path.Dir(reqPath)
if _, err := fs.Get(ctx, reqDir, &fs.GetArgs{}); err != nil {
if errs.IsObjectNotFound(err) {
return http.StatusConflict, err
}
return http.StatusMethodNotAllowed, err
}
if err := fs.MakeDir(ctx, reqPath); err != nil {
if os.IsNotExist(err) {
return http.StatusConflict, err
@ -521,13 +536,13 @@ func (h *Handler) handleLock(w http.ResponseWriter, r *http.Request) (retStatus
}
}
reqPath, status, err := h.stripPrefix(r.URL.Path)
if err != nil {
return status, err
}
reqPath, err = user.JoinPath(reqPath)
if err != nil {
return 403, err
}
if err != nil {
return status, err
}
ld = LockDetails{
Root: reqPath,
Duration: duration,