Skip to content

Commit 91d2844

Browse files
zeripathAbdulrhmnGhanem
authored andcommitted
Ensure responses are context.ResponseWriters (go-gitea#19843)
In order for web.Wrap to be able to detect if a response has been written we need to wrap any non-context.ResponseWriters as a such. Otherwise responses will be incorrectly detected as non-written to and handlers can double run. In the case of GZip this handler will change the response to a non-context.RW and this failure to correctly detect response writing causes fallthrough and a NPE. Fix go-gitea#19839 Signed-off-by: Andrew Thornton <[email protected]>
1 parent b7ddd52 commit 91d2844

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

modules/web/wrap_convert.go

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func convertHandler(handler interface{}) wrappedHandlerFunc {
2121
case http.HandlerFunc:
2222
return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) {
2323
routing.UpdateFuncInfo(req.Context(), funcInfo)
24+
if _, ok := resp.(context.ResponseWriter); !ok {
25+
resp = context.NewResponse(resp)
26+
}
2427
t(resp, req)
2528
if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 {
2629
done = true
@@ -92,6 +95,9 @@ func convertHandler(handler interface{}) wrappedHandlerFunc {
9295
next = wrapInternal(others)
9396
}
9497
routing.UpdateFuncInfo(req.Context(), funcInfo)
98+
if _, ok := resp.(context.ResponseWriter); !ok {
99+
resp = context.NewResponse(resp)
100+
}
95101
t(next).ServeHTTP(resp, req)
96102
if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 {
97103
done = true

0 commit comments

Comments
 (0)