From e1781e2db10b1c3580837491198ea2f7ef3c0ab4 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 4 Jul 2014 00:12:35 +0200 Subject: [PATCH] Fixes "http: multiple response.WriteHeader calls" in 404 [Issue #29] --- gin.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gin.go b/gin.go index 8a4ed8c..3b584d9 100644 --- a/gin.go +++ b/gin.go @@ -129,13 +129,11 @@ func (engine *Engine) CacheStress() float32 { func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) { handlers := engine.combineHandlers(engine.handlers404) c := engine.createContext(w, req, nil, handlers) - if engine.handlers404 == nil { - http.NotFound(c.Writer, c.Req) - } else { - c.Writer.WriteHeader(404) - } - + c.Writer.setStatus(404) c.Next() + if !c.Writer.Written() { + c.String(404, "404 page not found") + } engine.reuseContext(c) }