|
|
@ -24,6 +24,8 @@ const (
|
|
|
|
reason = "Request Timeout"
|
|
|
|
reason = "Request Timeout"
|
|
|
|
headerUpgrade = "Upgrade"
|
|
|
|
headerUpgrade = "Upgrade"
|
|
|
|
valueWebsocket = "websocket"
|
|
|
|
valueWebsocket = "websocket"
|
|
|
|
|
|
|
|
headerAccept = "Accept"
|
|
|
|
|
|
|
|
valueSSE = "text/event-stream"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// TimeoutHandler returns the handler with given timeout.
|
|
|
|
// TimeoutHandler returns the handler with given timeout.
|
|
|
@ -56,7 +58,9 @@ func (h *timeoutHandler) errorBody() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Header.Get(headerUpgrade) == valueWebsocket {
|
|
|
|
if r.Header.Get(headerUpgrade) == valueWebsocket ||
|
|
|
|
|
|
|
|
// Server-Sent Event ignore timeout.
|
|
|
|
|
|
|
|
r.Header.Get(headerAccept) == valueSSE {
|
|
|
|
h.handler.ServeHTTP(w, r)
|
|
|
|
h.handler.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -110,7 +114,7 @@ func (h *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
io.WriteString(w, h.errorBody())
|
|
|
|
_, _ = io.WriteString(w, h.errorBody())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
tw.timedOut = true
|
|
|
|
tw.timedOut = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|