mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
Fix SSE timeout will affected by http.Server 's WriteTimeout (#5024)
Co-authored-by: csbzy <chenshaobo65@mail.com> Co-authored-by: Kevin Wan <wanjunfeng@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/codec"
|
"github.com/zeromicro/go-zero/core/codec"
|
||||||
"github.com/zeromicro/go-zero/core/load"
|
"github.com/zeromicro/go-zero/core/load"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stat"
|
"github.com/zeromicro/go-zero/core/stat"
|
||||||
"github.com/zeromicro/go-zero/rest/chain"
|
"github.com/zeromicro/go-zero/rest/chain"
|
||||||
"github.com/zeromicro/go-zero/rest/handler"
|
"github.com/zeromicro/go-zero/rest/handler"
|
||||||
@@ -70,6 +71,11 @@ func buildSSERoutes(routes []Route) []Route {
|
|||||||
for i, route := range routes {
|
for i, route := range routes {
|
||||||
h := route.Handler
|
h := route.Handler
|
||||||
routes[i].Handler = func(w http.ResponseWriter, r *http.Request) {
|
routes[i].Handler = func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
rc := http.NewResponseController(w)
|
||||||
|
err := rc.SetWriteDeadline(time.Time{})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("set conn write deadline failed:%v", err)
|
||||||
|
}
|
||||||
w.Header().Set(header.ContentType, header.ContentTypeEventStream)
|
w.Header().Set(header.ContentType, header.ContentTypeEventStream)
|
||||||
w.Header().Set(header.CacheControl, header.CacheControlNoCache)
|
w.Header().Set(header.CacheControl, header.CacheControlNoCache)
|
||||||
w.Header().Set(header.Connection, header.ConnectionKeepAlive)
|
w.Header().Set(header.Connection, header.ConnectionKeepAlive)
|
||||||
|
|||||||
@@ -59,3 +59,8 @@ func (w *WithCodeResponseWriter) WriteHeader(code int) {
|
|||||||
w.Writer.WriteHeader(code)
|
w.Writer.WriteHeader(code)
|
||||||
w.Code = code
|
w.Code = code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unwrap returns the underlying ResponseWriter.
|
||||||
|
func (w *WithCodeResponseWriter) Unwrap() http.ResponseWriter {
|
||||||
|
return w.Writer
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user