From 4c121d159ca520bfb6a1b01095cd96a2a3ff390a 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: Wed, 20 Nov 2024 12:51:13 +0000 Subject: [PATCH] HTTP transport: Use dest as Host if not set --- 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 989ed1060b57..1cd7d05860b2 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 d0a86e8b4eb2..5ce52ee357f0 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.Domain() + } else if Host == "" { + Host = "www.example.com" + } + request := &http.Request{ Method: httpMethod, - Host: httpSettings.getRandomHost(), + Host: Host, Body: breader, URL: &url.URL{ Scheme: "https",