mirror of
https://github.com/labstack/echo.git
synced 2026-05-16 09:48:24 +02:00
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)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
return c.echo.JSONSerializer.Serialize(c, i, indent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user