Skip to content

Commit

Permalink
fix: add error handling for webdav mkcol according to RFC 4918 (Alist…
Browse files Browse the repository at this point in the history
…Go#5581)

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

* feat: update rfc reference

* fix: fix issue with uncorrect error handling
  • Loading branch information
Kuingsmile authored and gmugu committed May 27, 2024
1 parent 22cd135 commit 171cd65
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions server/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -521,12 +536,12 @@ func (h *Handler) handleLock(w http.ResponseWriter, r *http.Request) (retStatus
}
}
reqPath, status, err := h.stripPrefix(r.URL.Path)
reqPath, err = user.JoinPath(reqPath)
if err != nil {
return 403, err
return status, err
}
reqPath, err = user.JoinPath(reqPath)
if err != nil {
return status, err
return 403, err
}
ld = LockDetails{
Root: reqPath,
Expand Down

0 comments on commit 171cd65

Please sign in to comment.