bug fix
This commit is contained in:
parent
aea9f698ca
commit
1ed9060aa9
@ -27,6 +27,7 @@ type ReverseConfig struct {
|
||||
routes map[string]*SingleReverseConfig
|
||||
autogenCert bool //是否自动生成证书
|
||||
hostnameTlsCache map[string]*tls.Config //缓存证书
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
type SingleReverseConfig struct {
|
||||
|
@ -421,13 +421,18 @@ func (h *ReverseConfig) getCert(hostname string) *tls.Config {
|
||||
starlog.Errorln("Load X509 Key Pair Error:", err)
|
||||
return &tls.Config{}
|
||||
}
|
||||
|
||||
h.Lock()
|
||||
if h.hostnameTlsCache == nil {
|
||||
h.hostnameTlsCache = make(map[string]*tls.Config)
|
||||
}
|
||||
if tlsCfg, ok := h.hostnameTlsCache[hostname]; ok {
|
||||
h.Unlock()
|
||||
return tlsCfg
|
||||
}
|
||||
h.hostnameTlsCache[hostname] = &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
h.Unlock()
|
||||
return h.hostnameTlsCache[hostname]
|
||||
}
|
||||
|
||||
@ -457,10 +462,16 @@ func (h *ReverseConfig) autoGenCert(hostname string) *tls.Config {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
h.Lock()
|
||||
if h.hostnameTlsCache == nil {
|
||||
h.hostnameTlsCache = make(map[string]*tls.Config)
|
||||
}
|
||||
if tlsCfg, ok := h.hostnameTlsCache[hostname]; ok {
|
||||
h.Unlock()
|
||||
return tlsCfg
|
||||
}
|
||||
h.hostnameTlsCache[hostname] = &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
h.Unlock()
|
||||
return h.hostnameTlsCache[hostname]
|
||||
}
|
||||
|
||||
@ -472,12 +483,14 @@ func (h *ReverseConfig) Close() error {
|
||||
|
||||
func (h *SingleReverseConfig) dialTLS(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
var host string
|
||||
info := strings.Split(addr, ";;")
|
||||
if len(info) != 2 {
|
||||
addr = info[0]
|
||||
if h.ProxyHost != "" && h.ProxyHost != "$user" {
|
||||
host = h.ProxyHost
|
||||
} else if h.ProxyHost != "" {
|
||||
if val, ok := ctx.Value("realhost").(string); ok {
|
||||
host = val
|
||||
}
|
||||
} else {
|
||||
host = info[0]
|
||||
addr = info[1]
|
||||
host, _, _ = net.SplitHostPort(addr)
|
||||
}
|
||||
conn, err := net.DialTimeout(network, addr, time.Second*20)
|
||||
if err != nil {
|
||||
@ -510,12 +523,6 @@ func (h *SingleReverseConfig) dialTLS(ctx context.Context, network, addr string)
|
||||
}
|
||||
|
||||
func (h *SingleReverseConfig) dial(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
info := strings.Split(addr, ";;")
|
||||
if len(info) != 2 {
|
||||
addr = info[0]
|
||||
} else {
|
||||
addr = info[1]
|
||||
}
|
||||
conn, err := net.DialTimeout(network, addr, time.Second*20)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -564,11 +571,14 @@ func (h *SingleReverseConfig) newReverseProxy(key string, val *url.URL) error {
|
||||
if h.ProxyHost != "" {
|
||||
if h.ProxyHost != "$user" {
|
||||
req.Host = h.ProxyHost
|
||||
} else {
|
||||
ctx := context.WithValue(req.Context(), "realhost", req.Host)
|
||||
*req = *req.WithContext(ctx)
|
||||
}
|
||||
} else {
|
||||
req.Host = val.Host
|
||||
}
|
||||
req.URL.Host = req.Host + ";;" + val.Host
|
||||
req.URL.Host = val.Host
|
||||
req.URL.Path, req.URL.RawPath = joinURLPath(val, req.URL, key)
|
||||
if targetQuery == "" || req.URL.RawQuery == "" {
|
||||
req.URL.RawQuery = targetQuery + req.URL.RawQuery
|
||||
@ -679,6 +689,9 @@ func (h *SingleReverseConfig) ModifyRequest(req *http.Request, remote *url.URL)
|
||||
req.Header.Set(h.FilterSetKey, lastForwardIP)
|
||||
}
|
||||
}
|
||||
if len(h.ReplaceList) > 0 {
|
||||
req.Header.Set("Accept-Encoding", "deflate")
|
||||
}
|
||||
for _, v := range h.Cookie {
|
||||
req.AddCookie(&http.Cookie{
|
||||
Name: v[1],
|
||||
|
@ -1,3 +1,3 @@
|
||||
package version
|
||||
|
||||
var Version = "2.1.0.beta.19"
|
||||
var Version = "2.1.0.beta.19.250620"
|
||||
|
Loading…
x
Reference in New Issue
Block a user