From fb190d5c5e752c4c5a15f6a8a1ec575a60a726d8 Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 15 Apr 2026 20:33:43 +0300 Subject: [PATCH] fix: return non-nil channel when CloseNotifier is not supported --- response_writer.go | 2 +- response_writer_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/response_writer.go b/response_writer.go index 305322b6..7a67bfdf 100644 --- a/response_writer.go +++ b/response_writer.go @@ -134,7 +134,7 @@ func (w *responseWriter) CloseNotify() <-chan bool { if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok { return cn.CloseNotify() } - return nil + return make(chan bool) } // Flush implements the http.Flusher interface. diff --git a/response_writer_test.go b/response_writer_test.go index 02dbe4dd..a58068f0 100644 --- a/response_writer_test.go +++ b/response_writer_test.go @@ -118,7 +118,7 @@ func TestResponseWriterHijack(t *testing.T) { assert.True(t, w.Written()) ch := w.CloseNotify() - assert.Nil(t, ch) + assert.NotNil(t, ch) w.Flush() } @@ -338,7 +338,12 @@ func TestCloseNotifyWithoutCloseNotifier(t *testing.T) { w.reset(rw) 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) {