Improve logging
This commit is contained in:
parent
60dc513813
commit
64784b6b37
18
listener.go
18
listener.go
|
@ -79,7 +79,7 @@ func (l Listener) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
// Sanity checks:
|
// Sanity checks:
|
||||||
// - method is HTTP GET
|
// - method is HTTP GET
|
||||||
// - has request URI
|
// - has request URI
|
||||||
// - has Host header -> no!
|
// - has Host header -> no! this check should be omitted
|
||||||
// - has Connection: Upgrade
|
// - has Connection: Upgrade
|
||||||
// - has Upgrade: websocket
|
// - has Upgrade: websocket
|
||||||
// - has Sec-WebSocket-Version: 13
|
// - has Sec-WebSocket-Version: 13
|
||||||
|
@ -125,18 +125,18 @@ func (l Listener) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: remove all that debug spam
|
log.TRACE.To(logger).If(func(msg log.Fn) {
|
||||||
log.DEBUG.To(logger).Msg("In the websocket handler - yay!")
|
msg("Dumping HTTP headers:")
|
||||||
for k, v := range req.Header {
|
for k, v := range req.Header {
|
||||||
log.INFO.To(logger).Msg(" %v: %v", k, v[0])
|
msg(" %v: %v", k, v[0])
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
wsKey := head.Get("Sec-Websocket-Key")
|
wsKey := head.Get("Sec-Websocket-Key")
|
||||||
wsKey += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
wsKey += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
||||||
shakey := sha1.Sum([]byte(wsKey))
|
shakey := sha1.Sum([]byte(wsKey))
|
||||||
wsKey = base64.StdEncoding.EncodeToString(shakey[:])
|
wsKey = base64.StdEncoding.EncodeToString(shakey[:])
|
||||||
|
log.DEBUG.To(logger).Msg("Generated WebSocket-Accept: %v", wsKey)
|
||||||
log.INFO.To(logger).Msg("Generated WebSocket-Accept: ", wsKey)
|
|
||||||
// NOPE: we need to hijack the connection and send it manually!
|
// NOPE: we need to hijack the connection and send it manually!
|
||||||
//resp.Header().Set("Upgrade", "websocket")
|
//resp.Header().Set("Upgrade", "websocket")
|
||||||
//resp.Header().Set("Connection", "Upgrade")
|
//resp.Header().Set("Connection", "Upgrade")
|
||||||
|
@ -164,7 +164,7 @@ func (l Listener) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
// the client must not've sent any data before the handshake is complete
|
// the client must not've sent any data before the handshake is complete
|
||||||
if brw.Reader.Buffered() > 0 {
|
if brw.Reader.Buffered() > 0 {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
log.ERROR.To(logger).Msg("client send before handshake!")
|
log.ERROR.To(logger).Msg("client sent data before handshake!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user