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 (
"github.com/go-gost/core/logger"
md "github.com/go-gost/core/metadata"
netpkg "github.com/go-gost/x/internal/net"
sx "github.com/go-gost/x/internal/util/selector"
"github.com/go-gost/x/registry"
)
@ -177,6 +178,11 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
req.Header.Del("Proxy-Authorization")
switch h.md.hash {
case "host":
ctx = sx.ContextWithHash(ctx, &sx.Hash{Source: addr})
}
cc, err := h.router.Dial(ctx, network, addr)
if err != nil {
resp.StatusCode = http.StatusServiceUnavailable

View File

@ -12,6 +12,7 @@ type metadata struct {
probeResistance *probeResistance
enableUDP bool
header http.Header
hash string
}
func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
@ -21,6 +22,7 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
probeResistKeyX = "probe_resist"
knock = "knock"
enableUDP = "udp"
hash = "hash"
)
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
@ -45,6 +47,7 @@ func (h *httpHandler) parseMetadata(md mdata.Metadata) error {
}
}
h.md.enableUDP = mdutil.GetBool(md, enableUDP)
h.md.hash = mdutil.GetString(md, hash)
return nil
}