aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-05-31 21:27:44 +0100
committerGitHub <noreply@github.com>2022-05-31 21:27:44 +0100
commit730b9a5a624651e4821a043fe3f596c92be2df01 (patch)
tree41f848f7088ad6a2745048e2e2b3ba4bba6279a2 /modules
parent0e516949a446f509411bcd7b2654a048d37a91c5 (diff)
downloadgitea-730b9a5a624651e4821a043fe3f596c92be2df01.tar.gz
gitea-730b9a5a624651e4821a043fe3f596c92be2df01.zip
Ensure responses are context.ResponseWriters (#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 #19839 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/web/wrap_convert.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/web/wrap_convert.go b/modules/web/wrap_convert.go
index 8dc4e6d62b..b7bcbc6439 100644
--- a/modules/web/wrap_convert.go
+++ b/modules/web/wrap_convert.go
@@ -21,6 +21,9 @@ func convertHandler(handler interface{}) wrappedHandlerFunc {
case http.HandlerFunc:
return func(resp http.ResponseWriter, req *http.Request, others ...wrappedHandlerFunc) (done bool, deferrable func()) {
routing.UpdateFuncInfo(req.Context(), funcInfo)
+ if _, ok := resp.(context.ResponseWriter); !ok {
+ resp = context.NewResponse(resp)
+ }
t(resp, req)
if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 {
done = true
@@ -92,6 +95,9 @@ func convertHandler(handler interface{}) wrappedHandlerFunc {
next = wrapInternal(others)
}
routing.UpdateFuncInfo(req.Context(), funcInfo)
+ if _, ok := resp.(context.ResponseWriter); !ok {
+ resp = context.NewResponse(resp)
+ }
t(next).ServeHTTP(resp, req)
if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 {
done = true