mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:34:01 +03:00
Add support of proxy protocol
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package proxyprotocol
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/pires/go-proxyproto"
|
||||
)
|
||||
|
||||
type ListenerAdapter struct {
|
||||
proxyproto.Listener
|
||||
}
|
||||
|
||||
func (l *ListenerAdapter) Accept() (net.Conn, error) {
|
||||
conn, err := l.Listener.Accept()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return connWrapper{conn.(*proxyproto.Conn)}, nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package proxyprotocol
|
||||
|
||||
import "github.com/pires/go-proxyproto"
|
||||
|
||||
type connWrapper struct {
|
||||
*proxyproto.Conn
|
||||
}
|
||||
|
||||
func (c connWrapper) CloseRead() error {
|
||||
tcpConn, ok := c.TCPConn()
|
||||
if !ok {
|
||||
panic("we support only tcp connections")
|
||||
}
|
||||
|
||||
return tcpConn.CloseRead()
|
||||
}
|
||||
|
||||
func (c connWrapper) CloseWrite() error {
|
||||
tcpConn, ok := c.TCPConn()
|
||||
if !ok {
|
||||
panic("we support only tcp connections")
|
||||
}
|
||||
|
||||
return tcpConn.CloseWrite()
|
||||
}
|
||||
Reference in New Issue
Block a user