Skip to content

Commit f4f8ba3

Browse files
committed
Prevent superfluous response.WriteHeader (go-gitea#15456)
Backport go-gitea#15456 This PR simply checks the status before writing the header. Signed-off-by: Andrew Thornton <[email protected]>
1 parent fa3fe1e commit f4f8ba3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/context/response.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
package context
66

7-
import "net/http"
7+
import (
8+
"net/http"
9+
)
810

911
// ResponseWriter represents a response writer for HTTP
1012
type ResponseWriter interface {
@@ -60,8 +62,10 @@ func (r *Response) WriteHeader(statusCode int) {
6062
}
6163
r.beforeExecuted = true
6264
}
63-
r.status = statusCode
64-
r.ResponseWriter.WriteHeader(statusCode)
65+
if r.status == 0 {
66+
r.status = statusCode
67+
r.ResponseWriter.WriteHeader(statusCode)
68+
}
6569
}
6670

6771
// Flush flush cached data

0 commit comments

Comments
 (0)