mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 18:50:27 +08:00
优化代码
This commit is contained in:
@@ -40,6 +40,10 @@ func (this *BaseListener) buildTLSConfig() *tls.Config {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tlsPolicy == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
tlsPolicy.CheckOCSP()
|
tlsPolicy.CheckOCSP()
|
||||||
|
|
||||||
return tlsPolicy.TLSConfig(), nil
|
return tlsPolicy.TLSConfig(), nil
|
||||||
@@ -62,7 +66,7 @@ func (this *BaseListener) buildTLSConfig() *tls.Config {
|
|||||||
|
|
||||||
// 根据域名匹配证书
|
// 根据域名匹配证书
|
||||||
func (this *BaseListener) matchSSL(domain string) (*sslconfigs.SSLPolicy, *tls.Certificate, error) {
|
func (this *BaseListener) matchSSL(domain string) (*sslconfigs.SSLPolicy, *tls.Certificate, error) {
|
||||||
group := this.Group
|
var group = this.Group
|
||||||
|
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return nil, nil, errors.New("no configure found")
|
return nil, nil, errors.New("no configure found")
|
||||||
|
|||||||
@@ -139,10 +139,10 @@ func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http.
|
|||||||
// TLS域名
|
// TLS域名
|
||||||
if this.isIP(reqHost) {
|
if this.isIP(reqHost) {
|
||||||
if rawReq.TLS != nil {
|
if rawReq.TLS != nil {
|
||||||
serverName := rawReq.TLS.ServerName
|
var serverName = rawReq.TLS.ServerName
|
||||||
if len(serverName) > 0 {
|
if len(serverName) > 0 {
|
||||||
// 端口
|
// 端口
|
||||||
index := strings.LastIndex(reqHost, ":")
|
var index = strings.LastIndex(reqHost, ":")
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
reqHost = serverName + reqHost[index:]
|
reqHost = serverName + reqHost[index:]
|
||||||
} else {
|
} else {
|
||||||
@@ -154,7 +154,7 @@ func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http.
|
|||||||
|
|
||||||
// 防止空Host
|
// 防止空Host
|
||||||
if len(reqHost) == 0 {
|
if len(reqHost) == 0 {
|
||||||
ctx := rawReq.Context()
|
var ctx = rawReq.Context()
|
||||||
if ctx != nil {
|
if ctx != nil {
|
||||||
addr := ctx.Value(http.LocalAddrContextKey)
|
addr := ctx.Value(http.LocalAddrContextKey)
|
||||||
if addr != nil {
|
if addr != nil {
|
||||||
@@ -176,6 +176,8 @@ func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http.
|
|||||||
} else {
|
} else {
|
||||||
serverName = domain
|
serverName = domain
|
||||||
}
|
}
|
||||||
|
} else if !server.CNameAsDomain && server.CNameDomain == domain {
|
||||||
|
server = this.emptyServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绑定连接
|
// 绑定连接
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func (this *TCPListener) connectOrigin(serverId int64, reverseProxy *serverconfi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = errors.New("no origin server can be used")
|
err = errors.New("server '" + types.String(serverId) + "': no available origin server can be used")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ func (this *UDPListener) connectOrigin(serverId int64, reverseProxy *serverconfi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = errors.New("no origin server can be used")
|
err = errors.New("server '" + types.String(serverId) + "': no available origin server can be used")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user