Skip to content

Commit

Permalink
Fix X-Forwarded-For parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Fangliding authored Jul 17, 2024
1 parent 9e6d7a3 commit 2e1dd1b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions transport/internet/websocket/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ import (
var _ buf.Writer = (*connection)(nil)

// connection is a wrapper for net.Conn over WebSocket connection.
// remoteAddr is used to pass "virtual" remote IP addresses in X-Forwarded-For.
// so we shouldn't directly read it form conn.
type connection struct {
conn *websocket.Conn
reader io.Reader
conn *websocket.Conn
reader io.Reader
remoteAddr net.Addr
}

func NewConnection(conn *websocket.Conn, remoteAddr net.Addr, extraReader io.Reader) *connection {
return &connection{
conn: conn,
reader: extraReader,
conn: conn,
remoteAddr: remoteAddr,
reader: extraReader,
}
}

Expand Down Expand Up @@ -90,7 +94,7 @@ func (c *connection) LocalAddr() net.Addr {
}

func (c *connection) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
return c.remoteAddr
}

func (c *connection) SetDeadline(t time.Time) error {
Expand Down

0 comments on commit 2e1dd1b

Please sign in to comment.