Merge 44b40e45b451a38b6872bd0d81d6c5bd82fc2834 into 19b877fa50cbbb9282763099fb177a1e5cc5c850

This commit is contained in:
Griffin 2025-12-06 10:55:06 +08:00 committed by GitHub
commit af52c99cf5
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)
})
assert.Equal(t, "response writer does not support Hijack", err.Error())
assert.True(t, w.Written())
assert.Panics(t, func() {