0
這幾天我正在通過websoket使用Beego框架來發送消息。 但遇到錯誤信息http:multiple response.WriteHeader calls 問題在哪裏? 任何提示都會很棒!Golang http:multiple response.WriteHeader calls
func (this *WsController) Get() {
fmt.Println("connected")
handler(this.Ctx.ResponseWriter, this.Ctx.Request, this);
conn, err := upgrader.Upgrade(this.Ctx.ResponseWriter, this.Ctx.Request, nil)
if _, ok := err.(websocket.HandshakeError); ok {
http.Error(this.Ctx.ResponseWriter, "Not a websocket handshake", 400)
return
} else if err != nil {
return
}
fmt.Println("connected")
connection := consumer.New(beego.AppConfig.String("LoggregatorAddress"), &tls.Config{InsecureSkipVerify: true}, nil)
fmt.Println("===== Tailing messages")
msgChan, err := connection.Tail(this.Ctx.Input.Param(":appGuid"), this.Ctx.Input.Param(":token"))
if err != nil {
fmt.Printf("===== Error tailing: %v\n", err)
} else {
for msg := range msgChan {
// if closeRealTimeLogFlag{
// consumer.Close()
// break
// }
if err = conn.WriteMessage(websocket.TextMessage, msg.Message); err != nil {
fmt.Println(err)
}
fmt.Printf("%v \n", msg)
}
}
}
什麼的'handler'功能嗎? – Arjan 2014-11-04 11:57:08
http.Error()調用WriteHeader。因此,您的處理程序已經調用WriteHeader或upgradeder.Upgrade調用ResponseWriter上的Writeheader。 – Chrisport 2014-11-04 12:33:51
默認情況下,升級程序會調用http.Error。除非您在升級程序中設置了無操作錯誤功能,否則不應在應用程序代碼中調用http.Error。 – 2014-11-04 15:02:37