From 3d2e11eeed51387f45f90282877f82f5dca9c7c6 Mon Sep 17 00:00:00 2001 From: Hein Date: Tue, 19 May 2026 09:46:25 +0200 Subject: [PATCH] fix(restheadspec): always respond 200 OK regardless of result count in sendFormattedResponse --- pkg/restheadspec/handler.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index 386f80a..541a2d2 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -2561,10 +2561,8 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ dataLen := reflection.Len(data) // Add X-No-Data-Found header when no records were found - httpStatus := http.StatusOK if dataLen == 0 { w.SetHeader("X-No-Data-Found", "true") - httpStatus = http.StatusNoContent } // Apply normalization after header is set @@ -2588,7 +2586,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ switch options.ResponseFormat { case "simple": // Simple format: just return the data array - w.WriteHeader(httpStatus) + w.WriteHeader(http.StatusOK) if err := w.WriteJSON(data); err != nil { logger.Error("Failed to write JSON response: %v", err) } @@ -2600,7 +2598,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ if metadata != nil { response["count"] = metadata.Total } - w.WriteHeader(httpStatus) + w.WriteHeader(http.StatusOK) if err := w.WriteJSON(response); err != nil { logger.Error("Failed to write JSON response: %v", err) } @@ -2611,7 +2609,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ Data: data, Metadata: metadata, } - w.WriteHeader(httpStatus) + w.WriteHeader(http.StatusOK) if err := w.WriteJSON(response); err != nil { logger.Error("Failed to write JSON response: %v", err) }