diff --git a/http.go b/http.go index 15d5bd6b..6d016101 100644 --- a/http.go +++ b/http.go @@ -1157,8 +1157,8 @@ func (mux *serveMux) fireError(statusCode int, ctx *Context) { if errHandler == nil { errHandler = HandlerFunc(func(ctx *Context) { ctx.ResetBody() - ctx.SetBodyString(statusText[statusCode]) ctx.SetStatusCode(statusCode) + ctx.SetBodyString(statusText[statusCode]) }) mux.errorHandlers[statusCode] = errHandler } diff --git a/websocket/connection.go b/websocket/connection.go index 78c53960..3c152b5c 100644 --- a/websocket/connection.go +++ b/websocket/connection.go @@ -98,9 +98,25 @@ func (c *connection) writer() { return } - if err := c.write(websocket.TextMessage, msg); err != nil { + c.underline.SetWriteDeadline(time.Now().Add(c.server.config.WriteTimeout)) + res, err := c.underline.NextWriter(websocket.TextMessage) + if err != nil { return } + res.Write(msg) + + n := len(c.send) + for i := 0; i < n; i++ { + res.Write(<-c.send) + } + + if err := res.Close(); err != nil { + return + } + + // if err := c.write(websocket.TextMessage, msg); err != nil { + // return + // } case <-ticker.C: if err := c.write(websocket.PingMessage, []byte{}); err != nil {