fix webdav_mkcol response and add error handling webdav

Sun, 08 May 2022 12:27:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 08 May 2022 12:27:43 +0200
branch
webdav
changeset 344
70a9b945206a
parent 343
78ce9733a54f
child 345
5832e10fc59a

fix webdav_mkcol response and add error handling

src/server/plugins/postgresql/vfs.c file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/plugins/postgresql/vfs.c	Sun May 08 12:07:58 2022 +0200
+++ b/src/server/plugins/postgresql/vfs.c	Sun May 08 12:27:43 2022 +0200
@@ -433,6 +433,7 @@
     int err = pg_resolve_path(pg->connection, parent_path, &parent_id, &resource_id, &unused_oid, &resname, &iscollection, NULL, &ctx->vfs_errno);
     FREE(parent_path);
     if(err) {
+        ctx->vfs_errno = ENOENT;
         return 1;
     }
     
--- a/src/server/webdav/webdav.c	Sun May 08 12:07:58 2022 +0200
+++ b/src/server/webdav/webdav.c	Sun May 08 12:27:43 2022 +0200
@@ -513,7 +513,25 @@
         return REQ_ABORTED;
     }
     
-    int ret = webdav_vfs_op_do(op, WEBDAV_VFS_MKDIR);
+    int ret = REQ_ABORTED;
+    if(!webdav_vfs_op_do(op, WEBDAV_VFS_MKDIR)) {
+        pblock_nvinsert("content-length", "0", rq->srvhdrs);
+        protocol_status(sn, rq, 201, NULL);
+        protocol_start_response(sn, rq);
+        ret = REQ_PROCEED;
+    } else {
+        int status_code = 500;
+        if(op->vfs->vfs_errno == EEXIST) {
+            // 405 (Method Not Allowed) - MKCOL can only be executed on an unmapped URL.
+            status_code = 405;
+        } else if(op->vfs->vfs_errno == ENOENT) {
+            // 409 (Conflict) - A collection cannot be made at the Request-URI until
+            // one or more intermediate collections have been created.  The server
+            // MUST NOT create those intermediate collections automatically.
+            status_code = 409;
+        }
+        protocol_status(sn, rq, status_code, NULL);
+    }
     
     return ret;
 }

mercurial