Merge 3c28f41f5b880cdbc33555931a8ce8fe1a5b0500 into d3ffc9985281dcf4d3bef604cce4e662b1a327a6

This commit is contained in:
haesuo566 2026-03-17 10:03:33 +09:00 committed by GitHub
commit dc1cc4ea77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 24 deletions

View File

@ -1327,7 +1327,7 @@ func (c *Context) SSEvent(name string, message any) {
// indicates "Is client disconnected in middle of stream"
func (c *Context) Stream(step func(w io.Writer) bool) bool {
w := c.Writer
clientGone := w.CloseNotify()
clientGone := c.Request.Context().Done()
for {
select {
case <-clientGone:

View File

@ -3023,27 +3023,26 @@ func TestContextRenderDataFromReaderNoHeaders(t *testing.T) {
type TestResponseRecorder struct {
*httptest.ResponseRecorder
closeChannel chan bool
}
func (r *TestResponseRecorder) CloseNotify() <-chan bool {
return r.closeChannel
cancel context.CancelFunc
}
func (r *TestResponseRecorder) closeClient() {
r.closeChannel <- true
r.cancel()
}
func CreateTestResponseRecorder() *TestResponseRecorder {
func CreateTestResponseRecorder() (*TestResponseRecorder, *http.Request) {
ctx, cancel := context.WithCancel(context.Background())
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/", nil)
return &TestResponseRecorder{
httptest.NewRecorder(),
make(chan bool, 1),
}
cancel,
}, req
}
func TestContextStream(t *testing.T) {
w := CreateTestResponseRecorder()
w, req := CreateTestResponseRecorder()
c, _ := CreateTestContext(w)
c.Request = req
stopStream := true
c.Stream(func(w io.Writer) bool {
@ -3061,8 +3060,9 @@ func TestContextStream(t *testing.T) {
}
func TestContextStreamWithClientGone(t *testing.T) {
w := CreateTestResponseRecorder()
w, req := CreateTestResponseRecorder()
c, _ := CreateTestContext(w)
c.Request = req
c.Stream(func(writer io.Writer) bool {
defer func() {
@ -3079,7 +3079,7 @@ func TestContextStreamWithClientGone(t *testing.T) {
}
func TestContextResetInHandler(t *testing.T) {
w := CreateTestResponseRecorder()
w, _ := CreateTestResponseRecorder()
c, _ := CreateTestContext(w)
c.handlers = []HandlerFunc{

View File

@ -24,7 +24,6 @@ type ResponseWriter interface {
http.ResponseWriter
http.Hijacker
http.Flusher
http.CloseNotifier
// Status returns the HTTP response status code of the current request.
Status() int
@ -120,11 +119,6 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return w.ResponseWriter.(http.Hijacker).Hijack()
}
// CloseNotify implements the http.CloseNotifier interface.
func (w *responseWriter) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}
// Flush implements the http.Flusher interface.
func (w *responseWriter) Flush() {
w.WriteHeaderNow()

View File

@ -26,7 +26,6 @@ var (
_ http.ResponseWriter = ResponseWriter(&responseWriter{})
_ http.Hijacker = ResponseWriter(&responseWriter{})
_ http.Flusher = ResponseWriter(&responseWriter{})
_ http.CloseNotifier = ResponseWriter(&responseWriter{})
)
func init() {
@ -119,10 +118,6 @@ func TestResponseWriterHijack(t *testing.T) {
})
assert.True(t, w.Written())
assert.Panics(t, func() {
w.CloseNotify()
})
w.Flush()
}