Skip to content

Commit 8a439bf

Browse files
Fanglidingyuhan6665
authored andcommitted
Fix host in headers field does not work #3191
1 parent e2439c0 commit 8a439bf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

infra/conf/transport_internet.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (c *WebSocketConfig) Build() (proto.Message, error) {
181181
}
182182

183183
type HttpUpgradeConfig struct {
184-
Path string `json:"path"`
185-
Host string `json:"host"`
184+
Path string `json:"path"`
185+
Host string `json:"host"`
186186
Headers map[string]string `json:"headers"`
187-
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
187+
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
188188
}
189189

190190
// Build implements Buildable.
@@ -200,6 +200,14 @@ func (c *HttpUpgradeConfig) Build() (proto.Message, error) {
200200
path = u.String()
201201
}
202202
}
203+
// If http host is not set in the Host field, but in headers field, we add it to Host Field here.
204+
// If we don't do that, http host will be overwritten as address.
205+
// Host priority: Host field > headers field > address.
206+
if c.Host == "" && c.Headers["host"] != "" {
207+
c.Host = c.Headers["host"]
208+
} else if c.Host == "" && c.Headers["Host"] != "" {
209+
c.Host = c.Headers["Host"]
210+
}
203211
config := &httpupgrade.Config{
204212
Path: path,
205213
Host: c.Host,

0 commit comments

Comments
 (0)