From b593bc3e60ae89ada55449503ca4dc1bf52f6bb8 Mon Sep 17 00:00:00 2001 From: toim Date: Fri, 1 May 2026 21:11:17 +0300 Subject: [PATCH] Context.Json should not unwrap response and just wrap Response so other middlewares can use their own "wrapping" Responses and see the status code. --- context.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/context.go b/context.go index 5b9a7b149..4114ed4e9 100644 --- a/context.go +++ b/context.go @@ -479,13 +479,9 @@ func (c *Context) json(code int, i any, indent string) error { // as JSONSerializer.Serialize can fail, and in that case we need to delay sending status code to the client until // (global) error handler decides correct status code for the error to be sent to the client. // For that we need to use writer that can store the proposed status code until the first Write is called. - if r, err := UnwrapResponse(c.response); err == nil { - r.Status = code - } else { - resp := c.Response() - c.SetResponse(&delayedStatusWriter{ResponseWriter: resp, status: code}) - defer c.SetResponse(resp) - } + resp := c.Response() + c.SetResponse(&delayedStatusWriter{ResponseWriter: resp, status: code}) + defer c.SetResponse(resp) return c.echo.JSONSerializer.Serialize(c, i, indent) }