Skip to content

WrapHH should put the Writer back after calling c.Next() #7

@scr-oath

Description

@scr-oath

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()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions