From a361a03342a0de9ff9f30097e13eb7642205b0ae Mon Sep 17 00:00:00 2001 From: Sanghun Lee Date: Thu, 1 Aug 2024 01:11:47 +0900 Subject: [PATCH] fix: allow `DELETE` method requests to send body (#2571) Backported-from: main (24.09) Backported-to: 24.03 Backport-of: 2571 --- changes/2571.misc.md | 2 ++ src/ai/backend/manager/api/utils.py | 2 +- src/ai/backend/manager/api/vfolder.py | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changes/2571.misc.md diff --git a/changes/2571.misc.md b/changes/2571.misc.md new file mode 100644 index 0000000000..fd912a97e1 --- /dev/null +++ b/changes/2571.misc.md @@ -0,0 +1,2 @@ +* Add POST `/folders` API endpoints to replace DELETE APIs that require request body. +* Allow `DELETE` requests to have body data. diff --git a/src/ai/backend/manager/api/utils.py b/src/ai/backend/manager/api/utils.py index dacf76f20a..176e2da2ee 100644 --- a/src/ai/backend/manager/api/utils.py +++ b/src/ai/backend/manager/api/utils.py @@ -185,7 +185,7 @@ async def wrapped(request: web.Request, *args: P.args, **kwargs: P.kwargs) -> TA body: str = "" try: body_exists = request.can_read_body - if body_exists and request.method not in ("GET", "DELETE", "HEAD"): + if body_exists and request.method not in ("GET", "HEAD"): body = await request.text() if request.content_type == "text/yaml": orig_params = yaml.load(body, Loader=yaml.BaseLoader) diff --git a/src/ai/backend/manager/api/vfolder.py b/src/ai/backend/manager/api/vfolder.py index 734e3ff76c..703a229035 100644 --- a/src/ai/backend/manager/api/vfolder.py +++ b/src/ai/backend/manager/api/vfolder.py @@ -3491,6 +3491,7 @@ def create_app(default_cors_options): cors.add(add_route("POST", r"/{name}/request-download", create_download_session)) cors.add(add_route("POST", r"/{name}/move-file", move_file)) cors.add(add_route("POST", r"/{name}/rename-file", rename_file)) + cors.add(add_route("POST", r"/{name}/delete-files", delete_files)) cors.add(add_route("DELETE", r"/{name}/delete-files", delete_files)) cors.add(add_route("POST", r"/{name}/rename_file", rename_file)) # legacy underbar cors.add(add_route("DELETE", r"/{name}/delete_files", delete_files)) # legacy underbar @@ -3498,6 +3499,7 @@ def create_app(default_cors_options): cors.add(add_route("POST", r"/{name}/invite", invite)) cors.add(add_route("POST", r"/{name}/leave", leave)) cors.add(add_route("POST", r"/{name}/share", share)) + cors.add(add_route("POST", r"/{name}/unshare", unshare)) cors.add(add_route("DELETE", r"/{name}/unshare", unshare)) cors.add(add_route("POST", r"/{name}/clone", clone)) cors.add(add_route("POST", r"/purge", purge)) @@ -3508,12 +3510,14 @@ def create_app(default_cors_options): cors.add(add_route("POST", r"/invitations/update/{inv_id}", update_invitation)) cors.add(add_route("GET", r"/invitations/list", invitations)) cors.add(add_route("POST", r"/invitations/accept", accept_invitation)) + cors.add(add_route("POST", r"/invitations/delete", delete_invitation)) cors.add(add_route("DELETE", r"/invitations/delete", delete_invitation)) cors.add(add_route("GET", r"/_/shared", list_shared_vfolders)) cors.add(add_route("POST", r"/_/shared", update_shared_vfolder)) cors.add(add_route("GET", r"/_/fstab", get_fstab_contents)) cors.add(add_route("GET", r"/_/mounts", list_mounts)) cors.add(add_route("POST", r"/_/mounts", mount_host)) + cors.add(add_route("POST", r"/_/umounts", umount_host)) cors.add(add_route("DELETE", r"/_/mounts", umount_host)) cors.add(add_route("POST", r"/_/change-ownership", change_vfolder_ownership)) cors.add(add_route("GET", r"/_/quota", get_quota))