Răsfoiți Sursa

HTTP transport: Use dest as Host if not set (#4038)

风扇滑翔翼 1 an în urmă
părinte
comite
0a252ac15d
2 a modificat fișierele cu 9 adăugiri și 2 ștergeri
  1. 1 1
      transport/internet/http/config.go
  2. 8 1
      transport/internet/http/dialer.go

+ 1 - 1
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
 }

+ 8 - 1
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",