From a9e4995d762db81a8ed29a1c7494728f35effc02 Mon Sep 17 00:00:00 2001 From: 7y-9 Date: Wed, 10 Jun 2026 02:45:14 +0800 Subject: [PATCH] fix(http): accept no content delete responses (#9893) * fix(http): accept no content delete responses Problem: util/http.Delete reports an error for a successful HTTP 204 No Content response. Root cause: Delete only treats 200 OK, 202 Accepted, and 404 Not Found as non-error responses, omitting the standard 204 status commonly returned by DELETE endpoints. Fix: Include http.StatusNoContent in the Delete success status set. Reproduction: go test ./weed/util/http -run TestDeleteTreatsNoContentAsSuccess -count=1 fails before the fix with an empty error for a 204 response. Validation: go test ./weed/util/http -run TestDeleteTreatsNoContentAsSuccess -count=1; go test ./weed/util/http -count=1; git diff --check; git diff --cached --check Co-authored-by: Codex * Update weed/util/http/http_global_client_util_test.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Codex Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- weed/util/http/http_global_client_util.go | 2 +- weed/util/http/http_global_client_util_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/weed/util/http/http_global_client_util.go b/weed/util/http/http_global_client_util.go index a8adddb10..dc778b56e 100644 --- a/weed/util/http/http_global_client_util.go +++ b/weed/util/http/http_global_client_util.go @@ -172,7 +172,7 @@ func Delete(url string, jwt string) error { return err } switch resp.StatusCode { - case http.StatusNotFound, http.StatusAccepted, http.StatusOK: + case http.StatusNotFound, http.StatusNoContent, http.StatusAccepted, http.StatusOK: return nil } m := make(map[string]interface{}) diff --git a/weed/util/http/http_global_client_util_test.go b/weed/util/http/http_global_client_util_test.go index 487d23768..74b103559 100644 --- a/weed/util/http/http_global_client_util_test.go +++ b/weed/util/http/http_global_client_util_test.go @@ -103,6 +103,24 @@ func TestDeleteReturnsInvalidRequestErrorBeforeAddingAuth(t *testing.T) { } } +func TestDeleteTreatsNoContentAsSuccess(t *testing.T) { + InitGlobalHttpClient() + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodDelete { + t.Errorf("expected DELETE, got %s", r.Method) + w.WriteHeader(http.StatusBadRequest) + return + } + w.WriteHeader(http.StatusNoContent) + })) + defer server.Close() + + if err := Delete(server.URL, ""); err != nil { + t.Fatalf("expected 204 DELETE to succeed, got %v", err) + } +} + func TestDeleteProxiedReturnsInvalidRequestErrorBeforeAddingAuth(t *testing.T) { defer func() { if r := recover(); r != nil {