update github.com/pires/go-proxyproto to v0.5.0

This commit is contained in:
fatedier
2021-06-20 23:57:41 +08:00
parent 3f11b6a082
commit fe4e9b55f3
14 changed files with 127 additions and 43 deletions

View File

@@ -5,6 +5,7 @@ import (
"net"
libnet "github.com/fatedier/frp/pkg/util/net"
"github.com/fatedier/frp/test/e2e/pkg/rpc"
)
type Type string
@@ -20,9 +21,6 @@ type Server struct {
bindAddr string
bindPort int
respContent []byte
bufSize int64
echoMode bool
l net.Listener
}
@@ -33,7 +31,6 @@ func New(netType Type, options ...Option) *Server {
s := &Server{
netType: netType,
bindAddr: "127.0.0.1",
bufSize: 2048,
}
for _, option := range options {
@@ -63,20 +60,6 @@ func WithRespContent(content []byte) Option {
}
}
func WithBufSize(bufSize int64) Option {
return func(s *Server) *Server {
s.bufSize = bufSize
return s
}
}
func WithEchoMode(echoMode bool) Option {
return func(s *Server) *Server {
s.echoMode = echoMode
return s
}
}
func (s *Server) Run() error {
if err := s.initListener(); err != nil {
return err
@@ -118,18 +101,16 @@ func (s *Server) initListener() (err error) {
func (s *Server) handle(c net.Conn) {
defer c.Close()
buf := make([]byte, s.bufSize)
for {
n, err := c.Read(buf)
buf, err := rpc.ReadBytes(c)
if err != nil {
return
}
if s.echoMode {
c.Write(buf[:n])
} else {
c.Write(s.respContent)
if len(s.respContent) > 0 {
buf = s.respContent
}
rpc.WriteBytes(c, buf)
}
}