diff --git a/dns/transport/https.go b/dns/transport/https.go index 6c09f328..1cfb2574 100644 --- a/dns/transport/https.go +++ b/dns/transport/https.go @@ -62,9 +62,20 @@ func NewHTTPS(ctx context.Context, logger log.ContextLogger, tag string, options if !common.Contains(tlsConfig.NextProtos(), "http/1.1") { tlsConfig.SetNextProtos(append(tlsConfig.NextProtos(), "http/1.1")) } + headers := options.Headers.Build() + host := headers.Get("Host") + if host != "" { + headers.Del("Host") + } else { + if tlsConfig.ServerName() != "" { + host = tlsConfig.ServerName() + } else { + host = options.Server + } + } destinationURL := url.URL{ Scheme: "https", - Host: options.Host, + Host: host, } if destinationURL.Host == "" { destinationURL.Host = options.Server @@ -89,7 +100,7 @@ func NewHTTPS(ctx context.Context, logger log.ContextLogger, tag string, options logger, transportDialer, &destinationURL, - options.Headers.Build(), + headers, serverAddr, tlsConfig, ), nil diff --git a/dns/transport/quic/http3.go b/dns/transport/quic/http3.go index dc2b72f9..43f284d2 100644 --- a/dns/transport/quic/http3.go +++ b/dns/transport/quic/http3.go @@ -60,9 +60,20 @@ func NewHTTP3(ctx context.Context, logger log.ContextLogger, tag string, options if err != nil { return nil, err } + headers := options.Headers.Build() + host := headers.Get("Host") + if host != "" { + headers.Del("Host") + } else { + if tlsConfig.ServerName() != "" { + host = tlsConfig.ServerName() + } else { + host = options.Server + } + } destinationURL := url.URL{ Scheme: "HTTP3", - Host: options.Host, + Host: host, } if destinationURL.Host == "" { destinationURL.Host = options.Server @@ -87,7 +98,7 @@ func NewHTTP3(ctx context.Context, logger log.ContextLogger, tag string, options logger: logger, dialer: transportDialer, destination: &destinationURL, - headers: options.Headers.Build(), + headers: headers, transport: &http3.Transport{ Dial: func(ctx context.Context, addr string, tlsCfg *tls.STDConfig, cfg *quic.Config) (quic.EarlyConnection, error) { destinationAddr := M.ParseSocksaddr(addr) diff --git a/option/dns.go b/option/dns.go index 51553385..7260f8f3 100644 --- a/option/dns.go +++ b/option/dns.go @@ -281,7 +281,6 @@ type RemoteTLSDNSServerOptions struct { type RemoteHTTPSDNSServerOptions struct { RemoteTLSDNSServerOptions - Host string `json:"host,omitempty"` Path string `json:"path,omitempty"` Method string `json:"method,omitempty"` Headers badoption.HTTPHeader `json:"headers,omitempty"`