mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-06 20:18:19 +08:00
Merge 1182339849d2712dc7d90aac8f28c86a8f57a8de into 5f4f9643258dc2a65e684b63f12c8d543c936c67
This commit is contained in:
commit
1a0b1664f5
@ -117,12 +117,19 @@ 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, http.ErrNotSupported
|
||||
}
|
||||
return hijacker.Hijack()
|
||||
}
|
||||
|
||||
// CloseNotify implements the http.CloseNotifier interface.
|
||||
func (w *responseWriter) CloseNotify() <-chan bool {
|
||||
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
|
||||
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
|
||||
return cn.CloseNotify()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Flush implements the http.Flusher interface.
|
||||
|
||||
@ -113,15 +113,16 @@ func TestResponseWriterHijack(t *testing.T) {
|
||||
writer.reset(testWriter)
|
||||
w := ResponseWriter(writer)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
_, _, err := w.Hijack()
|
||||
require.NoError(t, err)
|
||||
})
|
||||
// httptest.ResponseRecorder doesn't implement http.Hijacker; return
|
||||
// http.ErrNotSupported instead of panicking (#4638).
|
||||
conn, buf, err := w.Hijack()
|
||||
assert.Nil(t, conn)
|
||||
assert.Nil(t, buf)
|
||||
require.ErrorIs(t, err, http.ErrNotSupported)
|
||||
assert.True(t, w.Written())
|
||||
|
||||
assert.Panics(t, func() {
|
||||
w.CloseNotify()
|
||||
})
|
||||
// CloseNotify on a non-CloseNotifier returns nil instead of panicking.
|
||||
assert.Nil(t, w.CloseNotify())
|
||||
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user