From 00e55dd2235baae4d07e07c1517b83f705381dc5 Mon Sep 17 00:00:00 2001 From: zeripath Date: Thu, 15 Apr 2021 11:02:42 +0100 Subject: [PATCH] Prevent superfluous response.WriteHeader (#15456) (#15476) Backport #15456 This PR simply checks the status before writing the header. Signed-off-by: Andrew Thornton --- modules/context/response.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/context/response.go b/modules/context/response.go index bdbbb97af..4ffbd230a 100644 --- a/modules/context/response.go +++ b/modules/context/response.go @@ -4,7 +4,9 @@ package context -import "net/http" +import ( + "net/http" +) // ResponseWriter represents a response writer for HTTP type ResponseWriter interface { @@ -60,8 +62,10 @@ func (r *Response) WriteHeader(statusCode int) { } r.beforeExecuted = true } - r.status = statusCode - r.ResponseWriter.WriteHeader(statusCode) + if r.status == 0 { + r.status = statusCode + r.ResponseWriter.WriteHeader(statusCode) + } } // Flush flush cached data