From 0a252ac15d34e7c23a1d3807a89bfca51cbb559b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Thu, 21 Nov 2024 13:42:19 +0800 Subject: [PATCH] HTTP transport: Use dest as Host if not set (#4038) --- transport/internet/http/config.go | 2 +- transport/internet/http/dialer.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/transport/internet/http/config.go b/transport/internet/http/config.go index 989ed106..1cd7d058 100644 --- a/transport/internet/http/config.go +++ b/transport/internet/http/config.go @@ -8,7 +8,7 @@ import ( func (c *Config) getHosts() []string { if len(c.Host) == 0 { - return []string{"www.example.com"} + return []string{""} } return c.Host } diff --git a/transport/internet/http/dialer.go b/transport/internet/http/dialer.go index d0a86e8b..42a9f9b3 100644 --- a/transport/internet/http/dialer.go +++ b/transport/internet/http/dialer.go @@ -215,9 +215,16 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me } } + Host := httpSettings.getRandomHost() + if Host == "" && net.ParseAddress(dest.NetAddr()).Family().IsDomain() { + Host = dest.Address.String() + } else if Host == "" { + Host = "www.example.com" + } + request := &http.Request{ Method: httpMethod, - Host: httpSettings.getRandomHost(), + Host: Host, Body: breader, URL: &url.URL{ Scheme: "https",