Skip to content

Commit

Permalink
bug: Websockets not working when log middleware is used
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidapaulopt committed Oct 30, 2024
1 parent fde5384 commit 6889f84
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/core/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package core

import (
"bufio"
"errors"
"net"
"net/http"
"os"

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6889f84

Please sign in to comment.