fix proxy protocol

This commit is contained in:
ginuerzh
2022-09-28 11:47:56 +08:00
parent cf20abf656
commit a1255e52d8
41 changed files with 524 additions and 180 deletions

View File

@ -21,6 +21,7 @@ import (
md "github.com/go-gost/core/metadata"
dissector "github.com/go-gost/tls-dissector"
netpkg "github.com/go-gost/x/internal/net"
sx "github.com/go-gost/x/internal/util/selector"
"github.com/go-gost/x/registry"
)
@ -121,6 +122,11 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
return nil
}
switch h.md.hash {
case "host":
ctx = sx.ContextWithHash(ctx, &sx.Hash{Source: host})
}
cc, err := h.router.Dial(ctx, "tcp", host)
if err != nil {
log.Error(err)
@ -179,6 +185,11 @@ func (h *sniHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr ne
return nil
}
switch h.md.hash {
case "host":
ctx = sx.ContextWithHash(ctx, &sx.Hash{Source: host})
}
cc, err := h.router.Dial(ctx, "tcp", host)
if err != nil {
log.Error(err)

View File

@ -9,13 +9,16 @@ import (
type metadata struct {
readTimeout time.Duration
hash string
}
func (h *sniHandler) parseMetadata(md mdata.Metadata) (err error) {
const (
readTimeout = "readTimeout"
hash = "hash"
)
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
h.md.hash = mdutil.GetString(md, hash)
return
}