Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend, net: Support compression protocol #373

Merged
merged 16 commits into from
Oct 9, 2023
Prev Previous commit
fix proxy peek
  • Loading branch information
djshow832 committed Oct 9, 2023
commit 3e1c136b74dbf6cb9d69a3f6ecfcb8cd8f121309
9 changes: 3 additions & 6 deletions pkg/proxy/net/proxy.go
Original file line number Diff line number Diff line change
@@ -63,9 +63,6 @@ func (prw *proxyReadWriter) Read(b []byte) (int, error) {
return 0, errors.Wrap(ErrReadConn, err)
}
if bytes.Equal(header[:], proxyprotocol.MagicV2[:4]) {
if _, err = prw.Discard(4); err != nil {
return 0, err
}
proxyHeader, err := prw.parseProxyV2()
if err != nil {
return 0, errors.Wrap(ErrReadConn, err)
@@ -99,16 +96,16 @@ func (prw *proxyReadWriter) Write(p []byte) (n int, err error) {
}

func (prw *proxyReadWriter) parseProxyV2() (*proxyprotocol.Proxy, error) {
rem, err := prw.packetReadWriter.Peek(8)
rem, err := prw.packetReadWriter.Peek(len(proxyprotocol.MagicV2))
if err != nil {
return nil, errors.WithStack(errors.Wrap(ErrReadConn, err))
}
if !bytes.Equal(rem, proxyprotocol.MagicV2[4:]) {
if !bytes.Equal(rem, proxyprotocol.MagicV2) {
return nil, nil
}

// yes, it is proxyV2
_, err = prw.packetReadWriter.Discard(8)
_, err = prw.packetReadWriter.Discard(len(proxyprotocol.MagicV2))
if err != nil {
return nil, errors.WithStack(errors.Wrap(ErrReadConn, err))
}
Loading