You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DefaultHTTPErrorHandler keeps stale Content-Encoding and Content-Length on error responses #3242
A handler may set Content-Encoding or Content-Length for the response it plans to send, for example a precompressed file served with Content-Encoding: br, and then fail before writing anything. DefaultHTTPErrorHandler writes its own JSON (or empty HEAD) body but leaves those headers in place:
The client gets a plain JSON body labeled br with the wrong length, so decoding fails or the connection is cut short.
Expected
Before writing its body, the error handler should remove Content-Length and, when no middleware is wrapping the response writer, Content-Encoding. A wrapping middleware such as a compressor may encode the error body itself, so in that case Content-Encoding is left alone.
Scope update for the fix in #3243, which differs from the "Expected" section above in two ways:
DefaultHTTPErrorHandler and ProblemDetailsHTTPErrorHandler remove Content-Disposition too, so an error after c.Attachment no longer downloads the error JSON as the attachment.
Content-Encoding is removed even when a middleware wraps the response. Keeping it for wrapped writers let a stale br survive under Gzip + RequestLogger (HandleError: true), and Gzip then passed the plain JSON through labeled br. Echo's Gzip sets its own Content-Encoding only when it starts compressing, so it is not affected. A third-party compressor that sets the header before writing would need to set it again.
Content-Type, Content-Range, ETag and Last-Modified are kept, because they can be meant for the error response (a vendor media type, a 416, a 304).
Activity
vishr commentedon Nov 20, 2026
Scope update for the fix in #3243, which differs from the "Expected" section above in two ways:
DefaultHTTPErrorHandlerandProblemDetailsHTTPErrorHandlerremoveContent-Dispositiontoo, so an error afterc.Attachmentno longer downloads the error JSON as the attachment.Content-Encodingis removed even when a middleware wraps the response. Keeping it for wrapped writers let a stalebrsurvive underGzip+RequestLogger(HandleError: true), andGzipthen passed the plain JSON through labeledbr. Echo'sGzipsets its ownContent-Encodingonly when it starts compressing, so it is not affected. A third-party compressor that sets the header before writing would need to set it again.Content-Type,Content-Range,ETagandLast-Modifiedare kept, because they can be meant for the error response (a vendor media type, a 416, a 304).