feat: support sse ignore timeout (#2041)

Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
chen quan
2024-02-17 15:06:45 +08:00
committed by GitHub
parent 0f1d4c6bca
commit 28cb2c5804
2 changed files with 22 additions and 2 deletions

View File

@@ -156,6 +156,22 @@ func TestTimeoutPanic(t *testing.T) {
})
}
func TestTimeoutSSE(t *testing.T) {
timeoutHandler := TimeoutHandler(time.Millisecond)
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Millisecond * 10)
r.Header.Set("Content-Type", "text/event-stream")
r.Header.Set("Cache-Control", "no-cache")
r.Header.Set("Connection", "keep-alive")
r.Header.Set("Transfer-Encoding", "chunked")
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req.Header.Set(headerAccept, valueSSE)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)
}
func TestTimeoutWebsocket(t *testing.T) {
timeoutHandler := TimeoutHandler(time.Millisecond)
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {