From 8de2f27043b00612986d96f37975cd4aa98b49c3 Mon Sep 17 00:00:00 2001 From: dyhkwong <50692134+dyhkwong@users.noreply.github.com> Date: Thu, 14 Sep 2023 08:27:36 +0800 Subject: [PATCH] fix protocol matching in routing (#2540) * remove invalid http2 sniffer * do not set metadata protocol for http inbound http inbound may have transport settings * fix doh metadata protocol --- app/dns/nameserver_doh.go | 2 +- common/protocol/http/sniff.go | 21 +++------------------ proxy/http/server.go | 4 +--- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index 5e2a63d00..6e1430e62 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -231,7 +231,7 @@ func (s *DoHNameServer) sendQuery(ctx context.Context, domain string, clientIP n } dnsCtx = session.ContextWithContent(dnsCtx, &session.Content{ - Protocol: "https", + Protocol: "tls", SkipDNSResolve: true, }) diff --git a/common/protocol/http/sniff.go b/common/protocol/http/sniff.go index 98e4e908e..fb60eea32 100644 --- a/common/protocol/http/sniff.go +++ b/common/protocol/http/sniff.go @@ -11,25 +11,12 @@ import ( type version byte -const ( - HTTP1 version = iota - HTTP2 -) - type SniffHeader struct { - version version - host string + host string } func (h *SniffHeader) Protocol() string { - switch h.version { - case HTTP1: - return "http1" - case HTTP2: - return "http2" - default: - return "unknown" - } + return "http1" } func (h *SniffHeader) Domain() string { @@ -62,9 +49,7 @@ func SniffHTTP(b []byte) (*SniffHeader, error) { return nil, err } - sh := &SniffHeader{ - version: HTTP1, - } + sh := &SniffHeader{} headers := bytes.Split(b, []byte{'\n'}) for i := 1; i < len(headers); i++ { diff --git a/proxy/http/server.go b/proxy/http/server.go index 26dc66b83..d698f3faf 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -242,9 +242,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri request.Header.Set("User-Agent", "") } - content := &session.Content{ - Protocol: "http/1.1", - } + content := &session.Content{} content.SetAttribute(":method", strings.ToUpper(request.Method)) content.SetAttribute(":path", request.URL.Path)