From e29237d593464c195833cbfe0cdef528e008ed2e Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 15 Oct 2025 10:28:31 +0800 Subject: [PATCH] fix(webdav): error code for missing parent in mkcol should be `409` instead of `404` (#2953) --- pkg/webdav/webdav.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/webdav/webdav.go b/pkg/webdav/webdav.go index fd630736..b8c3707d 100644 --- a/pkg/webdav/webdav.go +++ b/pkg/webdav/webdav.go @@ -212,7 +212,13 @@ func handleMkcol(c *gin.Context, user *ent.User, fm manager.FileManager) (status _, err = fm.Create(ctx, uri, types.FileTypeFolder, dbfs.WithNoChainedCreation(), dbfs.WithErrorOnConflict()) if err != nil { - return purposeStatusCodeFromError(err), err + code := purposeStatusCodeFromError(err) + if code == http.StatusNotFound { + // When the MKCOL operation creates a new collection resource, all ancestors MUST already exist, + // or the method MUST fail with a 409 (Conflict) status code. + return http.StatusConflict, err + } + return code, err } return http.StatusCreated, nil