-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior, if applicable:
- The code is
server
func newHttpServer(cfg config.ServerConf) {
server := rest.MustNewServer(cfg.RestConf, rest.WithCors())
server.AddRoute(rest.Route{
Method: http.MethodGet,
Path: "/sse",
Handler: SSEMsgHandler,
}, rest.WithSSE())
logz.Info().Msgf("start http server %s:%d", cfg.RestConf.Host, cfg.RestConf.Port)
go server.Start()
}
func SSEMsgHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "data: %s\n\n", "ping")
w.(http.Flusher).Flush()
<-r.Context().Done()
}
client
req, _ := http.NewRequest(http.MethodGet, _sseURL, nil)
resp, err := defaultHttpClient.Do(req)
//resp, err := defaultHttpClient.Get(uri)
if err != nil {
fmt.Printf("err %v\n", err)
return
}
reader := bufio.NewReader(resp.Body)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "data:") {
data := strings.TrimPrefix(line, "data:")
fmt.Printf("recv: %s\n", data)
} else if line == "" {
continue
}
}
-
The error is
server output log
08-17 15:12:47.083 ERR core/logc/logs.go:64 > set conn write deadline failed: feature not supported gozero_level=error span=a38166ca176dfb8f trace=ababff7795221871f106231e509e8253
2025/08/17 15:13:17 http: superfluous response.WriteHeader call from github.com/zeromicro/go-zero/rest/internal/response.(*WithCodeResponseWriter).WriteHeader (withcoderesponsewriter.go:65)
08-17 15:13:17.084 ERR rest/handler/loghandler.go:133 > [HTTP] 503 - GET /sse - 127.0.0.1:52461 - Go-http-client/1.1 - slowcall(30001.4ms) duration=30001.4ms gozero_level=slow span=a38166ca176dfb8f trace=ababff7795221871f106231e509e8253
08-17 15:13:17.085 ERR rest/handler/loghandler.go:151 > [HTTP] 503 - GET /sse - 127.0.0.1:52461 - Go-http-client/1.1
GET /sse HTTP/1.1
Host: 127.0.0.1:8083
Accept-Encoding: gzip
User-Agent: Go-http-client/1.1
duration=30001.4ms gozero_level=error span=a38166ca176dfb8f trace=ababff7795221871f106231e509e8253
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Environments (please complete the following information):**
- OS: [e.g. MAC]
- go-zero version [e.g. 1.9.0]
**More description**
Add any other context about the problem here.