mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-07 12:48:16 +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 {
|
if w.size < 0 {
|
||||||
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.
|
// CloseNotify implements the http.CloseNotifier interface.
|
||||||
func (w *responseWriter) CloseNotify() <-chan bool {
|
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.
|
// Flush implements the http.Flusher interface.
|
||||||
|
|||||||
@ -113,15 +113,16 @@ func TestResponseWriterHijack(t *testing.T) {
|
|||||||
writer.reset(testWriter)
|
writer.reset(testWriter)
|
||||||
w := ResponseWriter(writer)
|
w := ResponseWriter(writer)
|
||||||
|
|
||||||
assert.Panics(t, func() {
|
// httptest.ResponseRecorder doesn't implement http.Hijacker; return
|
||||||
_, _, err := w.Hijack()
|
// http.ErrNotSupported instead of panicking (#4638).
|
||||||
require.NoError(t, err)
|
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.True(t, w.Written())
|
||||||
|
|
||||||
assert.Panics(t, func() {
|
// CloseNotify on a non-CloseNotifier returns nil instead of panicking.
|
||||||
w.CloseNotify()
|
assert.Nil(t, w.CloseNotify())
|
||||||
})
|
|
||||||
|
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user