Ensure responses are context.ResponseWriters (#19843) (#19859)

* Ensure responses are context.ResponseWriters (#19843)

Backport #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>

* fix test

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
zeripath 2022-06-03 22:38:29 +01:00 committed by GitHub
parent cf6694e815
commit daf14b275a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 20 deletions

View file

@ -53,6 +53,7 @@ func TestRoute2(t *testing.T) {
tp := chi.URLParam(req, "type")
assert.EqualValues(t, "issues", tp)
route = 0
resp.WriteHeader(200)
})
r.Get("/{type:issues|pulls}/{index}", func(resp http.ResponseWriter, req *http.Request) {
@ -65,9 +66,8 @@ func TestRoute2(t *testing.T) {
index := chi.URLParam(req, "index")
assert.EqualValues(t, "1", index)
route = 1
resp.WriteHeader(200)
})
}, func(resp http.ResponseWriter, req *http.Request) {
resp.WriteHeader(200)
})
r.Group("/issues/{index}", func() {
@ -79,6 +79,7 @@ func TestRoute2(t *testing.T) {
index := chi.URLParam(req, "index")
assert.EqualValues(t, "1", index)
route = 2
resp.WriteHeader(200)
})
})
})