Skip to content

Commit fb190d5

Browse files
committed
fix: return non-nil channel when CloseNotifier is not supported
1 parent e16930e commit fb190d5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

response_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (w *responseWriter) CloseNotify() <-chan bool {
134134
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
135135
return cn.CloseNotify()
136136
}
137-
return nil
137+
return make(chan bool)
138138
}
139139

140140
// Flush implements the http.Flusher interface.

response_writer_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestResponseWriterHijack(t *testing.T) {
118118
assert.True(t, w.Written())
119119

120120
ch := w.CloseNotify()
121-
assert.Nil(t, ch)
121+
assert.NotNil(t, ch)
122122

123123
w.Flush()
124124
}
@@ -338,7 +338,12 @@ func TestCloseNotifyWithoutCloseNotifier(t *testing.T) {
338338
w.reset(rw)
339339

340340
ch := w.CloseNotify()
341-
assert.Nil(t, ch, "Expected CloseNotify channel to be nil when underlying writer does not support it")
341+
assert.NotNil(t, ch, "Expected non-nil channel when CloseNotifier is not supported")
342+
select {
343+
case <-ch:
344+
t.Fatal("channel should never fire when CloseNotifier is not supported")
345+
default:
346+
}
342347
}
343348

344349
func TestHijackWithoutHijacker(t *testing.T) {

0 commit comments

Comments
 (0)