Skip to content

Commit f16f84d

Browse files
authored
Context.Json should not unwrap response and just wrap Response so other middlewares can use their own "wrapping" Responses and see the status code. (#2964)
1 parent 96be504 commit f16f84d

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

context.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,9 @@ func (c *Context) json(code int, i any, indent string) error {
479479
// as JSONSerializer.Serialize can fail, and in that case we need to delay sending status code to the client until
480480
// (global) error handler decides correct status code for the error to be sent to the client.
481481
// For that we need to use writer that can store the proposed status code until the first Write is called.
482-
if r, err := UnwrapResponse(c.response); err == nil {
483-
r.Status = code
484-
} else {
485-
resp := c.Response()
486-
c.SetResponse(&delayedStatusWriter{ResponseWriter: resp, status: code})
487-
defer c.SetResponse(resp)
488-
}
482+
resp := c.Response()
483+
c.SetResponse(&delayedStatusWriter{ResponseWriter: resp, status: code})
484+
defer c.SetResponse(resp)
489485

490486
return c.echo.JSONSerializer.Serialize(c, i, indent)
491487
}

0 commit comments

Comments
 (0)