|
|
@ -7,26 +7,26 @@ import (
|
|
|
|
proxyproto "github.com/pires/go-proxyproto"
|
|
|
|
proxyproto "github.com/pires/go-proxyproto"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type listener struct {
|
|
|
|
type protoListener struct {
|
|
|
|
net.Listener
|
|
|
|
net.Listener
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type conn struct {
|
|
|
|
type protoConn struct {
|
|
|
|
net.Conn
|
|
|
|
net.Conn
|
|
|
|
headerDone bool
|
|
|
|
headerDone bool
|
|
|
|
r *bufio.Reader
|
|
|
|
r *bufio.Reader
|
|
|
|
proxy *proxyproto.Header
|
|
|
|
proxy *proxyproto.Header
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *listener) Accept() (net.Conn, error) {
|
|
|
|
func (l *protoListener) Accept() (net.Conn, error) {
|
|
|
|
c, err := l.Listener.Accept()
|
|
|
|
c, err := l.Listener.Accept()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &conn{Conn: c}, err
|
|
|
|
return &protoConn{Conn: c}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *conn) Read(buf []byte) (int, error) {
|
|
|
|
func (c *protoConn) Read(buf []byte) (int, error) {
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
if !c.headerDone {
|
|
|
|
if !c.headerDone {
|
|
|
|
c.r = bufio.NewReader(c.Conn)
|
|
|
|
c.r = bufio.NewReader(c.Conn)
|
|
|
@ -40,7 +40,7 @@ func (c *conn) Read(buf []byte) (int, error) {
|
|
|
|
return c.r.Read(buf)
|
|
|
|
return c.r.Read(buf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *conn) RemoteAddr() net.Addr {
|
|
|
|
func (c *protoConn) RemoteAddr() net.Addr {
|
|
|
|
if c.proxy == nil {
|
|
|
|
if c.proxy == nil {
|
|
|
|
return c.Conn.RemoteAddr()
|
|
|
|
return c.Conn.RemoteAddr()
|
|
|
|
}
|
|
|
|
}
|