Apparently, if wrapping middleware, say compression, but requesting a path that doesn't exist, when the 404 error is written, it is written by gin and the Writer is done/closed.
This bit of code seems to fix the issue…
// Run the next request in the middleware chain and return
func (h *nextRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
oldWriter := h.c.Writer
h.c.Writer = &wrappedResponseWriter{h.c.Writer, w}
defer func() {
h.c.Writer = oldWriter
}()
h.c.Next()
}
Apparently, if wrapping middleware, say compression, but requesting a path that doesn't exist, when the 404 error is written, it is written by gin and the Writer is done/closed.
This bit of code seems to fix the issue…