Merge 44b40e45b451a38b6872bd0d81d6c5bd82fc2834 into c3d1092b3b48addf6f9cd00fe274ec3bd14650eb

This commit is contained in:
Griffin 2025-10-11 21:19:01 +08:00 committed by GitHub
commit f126abdd61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -117,7 +117,11 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if w.size < 0 {
w.size = 0
}
return w.ResponseWriter.(http.Hijacker).Hijack()
hijacker, ok := w.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, errors.New("response writer does not support Hijack")
}
return hijacker.Hijack()
}
// CloseNotify implements the http.CloseNotifier interface.

View File

@ -113,10 +113,8 @@ func TestResponseWriterHijack(t *testing.T) {
writer.reset(testWriter)
w := ResponseWriter(writer)
assert.Panics(t, func() {
_, _, err := w.Hijack()
require.NoError(t, err)
})
_, _, err := w.Hijack()
assert.Equal(t, "response writer does not support Hijack", err.Error())
assert.True(t, w.Written())
assert.Panics(t, func() {