From ab97492f47dd57b94948360708488fdb63b4c377 Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Mon, 13 Apr 2026 09:38:49 +0800 Subject: [PATCH] fix: skip body encoding for all no-body HTTP status codes EncodeJSONResponse only skips body encoding for 204 No Content, but HTTP spec (RFC 9110) requires no message body for 1xx, 204, and 304 responses. Writing a body for 304 Not Modified causes net/http to return an error. Extend the check to skip body encoding for 1xx, 204, and 304. Fixes #1291 --- transport/http/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport/http/server.go b/transport/http/server.go index ab87d4ad0..1ffb39a58 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -174,7 +174,7 @@ func EncodeJSONResponse(_ context.Context, w http.ResponseWriter, response inter code = sc.StatusCode() } w.WriteHeader(code) - if code == http.StatusNoContent { + if code == http.StatusNoContent || code == http.StatusNotModified || (code >= 100 && code < 200) { return nil } return json.NewEncoder(w).Encode(response)