From fab744b8785c7279592164a9fbe6b83a925ccef8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 14:04:16 +0000 Subject: [PATCH] Add clarifying comments about X-No-Data-Found header timing - Added comments explaining why X-No-Data-Found is set before normalization - Header reflects database query result, not final response format - Clarifies that normalizeResultArray doesn't affect header logic - All tests passing Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com> --- pkg/restheadspec/handler.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index 8f7f895..dfe43d4 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -2216,6 +2216,8 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ } // Calculate data length after nil conversion + // Note: This is done BEFORE normalization because X-No-Data-Found indicates + // whether data was found in the database, not the final response format dataLen := reflection.Len(data) // Add X-No-Data-Found header when no records were found @@ -2223,6 +2225,9 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ w.SetHeader("X-No-Data-Found", "true") } + // Apply normalization after header is set + // normalizeResultArray may convert single-element arrays to objects, + // but the X-No-Data-Found header reflects the original query result if options.SingleRecordAsObject { data = h.normalizeResultArray(data) }