Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 0cbeafb

Browse files
committed
[proxy]如果客户端请求的Host为空,则自动指定为当前连接的服务器地址
1 parent 0fee13a commit 0cbeafb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

teaproxy/listener.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ func (this *Listener) handleHTTP(writer http.ResponseWriter, rawRequest *http.Re
389389

390390
// 域名
391391
reqHost := rawRequest.Host
392+
393+
// 防止空Host
394+
if len(reqHost) == 0 {
395+
ctx := rawRequest.Context()
396+
if ctx != nil {
397+
addr := ctx.Value(http.LocalAddrContextKey)
398+
if addr != nil {
399+
reqHost = addr.(net.Addr).String()
400+
}
401+
}
402+
}
403+
392404
domain, _, err := net.SplitHostPort(reqHost)
393405
if err != nil {
394406
domain = reqHost

teaproxy/request_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (this *Request) callBackend(writer *ResponseWriter) error {
104104
}
105105

106106
// 支持修改Host
107-
if header.Name == "Host" {
107+
if header.Name == "Host" && len(header.Value) > 0 {
108108
this.raw.Host = header.Value
109109
}
110110
}

0 commit comments

Comments
 (0)