From 8a439bf3f2ed8a6898dc3dbb1ab03fa99ce38809 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, 27 Mar 2024 21:06:56 +0800 Subject: [PATCH] Fix host in headers field does not work XTLS#3191 --- infra/conf/transport_internet.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 3feb7347..22e749d7 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -181,10 +181,10 @@ func (c *WebSocketConfig) Build() (proto.Message, error) { } type HttpUpgradeConfig struct { - Path string `json:"path"` - Host string `json:"host"` + Path string `json:"path"` + Host string `json:"host"` Headers map[string]string `json:"headers"` - AcceptProxyProtocol bool `json:"acceptProxyProtocol"` + AcceptProxyProtocol bool `json:"acceptProxyProtocol"` } // Build implements Buildable. @@ -200,6 +200,14 @@ func (c *HttpUpgradeConfig) Build() (proto.Message, error) { path = u.String() } } + // If http host is not set in the Host field, but in headers field, we add it to Host Field here. + // If we don't do that, http host will be overwritten as address. + // Host priority: Host field > headers field > address. + if c.Host == "" && c.Headers["host"] != "" { + c.Host = c.Headers["host"] + } else if c.Host == "" && c.Headers["Host"] != "" { + c.Host = c.Headers["Host"] + } config := &httpupgrade.Config{ Path: path, Host: c.Host,