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

Commit b144672

Browse files
committed
HTTPS支持TLS的SNI;修改拒绝非法域名的处理方式
1 parent ea0a75e commit b144672

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

teaproxy/listener.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ func (this *Listener) handleHTTP(writer http.ResponseWriter, rawRequest *http.Re
405405
// 域名
406406
reqHost := rawRequest.Host
407407

408+
// TLS域名
409+
if rawRequest.TLS != nil {
410+
serverName := rawRequest.TLS.ServerName
411+
if len(serverName) > 0 {
412+
reqHost = serverName
413+
}
414+
}
415+
408416
// 防止空Host
409417
if len(reqHost) == 0 {
410418
ctx := rawRequest.Context()
@@ -422,6 +430,18 @@ func (this *Listener) handleHTTP(writer http.ResponseWriter, rawRequest *http.Re
422430
}
423431
server, serverName := this.findNamedServer(domain)
424432
if server == nil {
433+
// 严格匹配域名模式下,我们拒绝用户访问
434+
if teaconfigs.SharedProxySetting().MatchDomainStrictly {
435+
hijacker, ok := writer.(http.Hijacker)
436+
if ok {
437+
conn, _, _ := hijacker.Hijack()
438+
if conn != nil {
439+
_ = conn.Close()
440+
return
441+
}
442+
}
443+
}
444+
425445
http.Error(writer, "404 page not found: '"+rawRequest.URL.String()+"'", http.StatusNotFound)
426446
return
427447
}

0 commit comments

Comments
 (0)