fix: fixing ping & memory leak

This commit is contained in:
2026-02-04 22:20:19 +07:00
parent 7f21b733ed
commit 07f7893a26
2 changed files with 52 additions and 33 deletions

View File

@@ -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)
})
}