mirror of
https://github.com/gin-gonic/gin.git
synced 2026-04-29 23:23:18 +08:00
fix: return non-nil channel when CloseNotifier is not supported
This commit is contained in:
parent
e16930e4aa
commit
fb190d5c5e
@ -134,7 +134,7 @@ func (w *responseWriter) CloseNotify() <-chan bool {
|
|||||||
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
|
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
|
||||||
return cn.CloseNotify()
|
return cn.CloseNotify()
|
||||||
}
|
}
|
||||||
return nil
|
return make(chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush implements the http.Flusher interface.
|
// Flush implements the http.Flusher interface.
|
||||||
|
|||||||
@ -118,7 +118,7 @@ func TestResponseWriterHijack(t *testing.T) {
|
|||||||
assert.True(t, w.Written())
|
assert.True(t, w.Written())
|
||||||
|
|
||||||
ch := w.CloseNotify()
|
ch := w.CloseNotify()
|
||||||
assert.Nil(t, ch)
|
assert.NotNil(t, ch)
|
||||||
|
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
@ -338,7 +338,12 @@ func TestCloseNotifyWithoutCloseNotifier(t *testing.T) {
|
|||||||
w.reset(rw)
|
w.reset(rw)
|
||||||
|
|
||||||
ch := w.CloseNotify()
|
ch := w.CloseNotify()
|
||||||
assert.Nil(t, ch, "Expected CloseNotify channel to be nil when underlying writer does not support it")
|
assert.NotNil(t, ch, "Expected non-nil channel when CloseNotifier is not supported")
|
||||||
|
select {
|
||||||
|
case <-ch:
|
||||||
|
t.Fatal("channel should never fire when CloseNotifier is not supported")
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHijackWithoutHijacker(t *testing.T) {
|
func TestHijackWithoutHijacker(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user