fix: fixing ping & memory leak
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -81,6 +82,7 @@ func (b *SafeWebsocketServerBuilder) HandleFuncWebsocket(pattern string, subscri
|
||||
}
|
||||
c := internal.NewClient(conn, subscribedPath)
|
||||
h.Register <- c
|
||||
|
||||
go internal.WritePump(c, h)
|
||||
go internal.ReadPump(c, h)
|
||||
go writeFunc(h.Broadcast)
|
||||
@@ -110,13 +112,17 @@ type SafeWebsocketServer struct {
|
||||
|
||||
func (s *SafeWebsocketServer) AuthMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("X-MBX-APIKEY") != s.apiKey {
|
||||
providedKey := r.Header.Get("X-MBX-APIKEY")
|
||||
expectedKey := s.apiKey
|
||||
|
||||
if subtle.ConstantTimeCompare([]byte(providedKey), []byte(expectedKey)) != 1 {
|
||||
internal.ErrorResponse(w, internal.NewStatusMessage().
|
||||
StatusCode(http.StatusForbidden).
|
||||
Message("X-MBX-APIKEY is missing").
|
||||
Build())
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user