From 6889f84aabb1ef4c70e96ff62015387cd74c6727 Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Wed, 30 Oct 2024 12:03:22 +0000 Subject: [PATCH] bug: Websockets not working when log middleware is used --- internal/core/log.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/core/log.go b/internal/core/log.go index 45e3c88..eba25b2 100644 --- a/internal/core/log.go +++ b/internal/core/log.go @@ -4,6 +4,9 @@ package core import ( + "bufio" + "errors" + "net" "net/http" "os" @@ -61,6 +64,14 @@ func (r *LogRecord) Write(data []byte) (int, error) { return n, err } +func (r *LogRecord) Hijack() (net.Conn, *bufio.ReadWriter, error) { + h, ok := r.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("hijack not supported") + } + return h.Hijack() +} + // LoggerMiddleware is a middleware function that logs incoming HTTP requests. func (l *Logger) LoggerMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {