mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
Fix(vmess): set current server name in tls
This commit is contained in:
parent
4c7da630f5
commit
8ded4918b2
|
@ -3,6 +3,7 @@ package obfs
|
|||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/Dreamacro/clash/component/vmess"
|
||||
)
|
||||
|
@ -17,11 +18,16 @@ type WebsocketOption struct {
|
|||
|
||||
// NewWebsocketObfs return a HTTPObfs
|
||||
func NewWebsocketObfs(conn net.Conn, option *WebsocketOption) (net.Conn, error) {
|
||||
header := http.Header{}
|
||||
for k, v := range option.Headers {
|
||||
header.Add(k, v)
|
||||
}
|
||||
|
||||
config := &vmess.WebsocketConfig{
|
||||
Host: option.Host,
|
||||
Path: option.Path,
|
||||
TLS: option.TLSConfig != nil,
|
||||
Headers: option.Headers,
|
||||
Headers: header,
|
||||
TLSConfig: option.TLSConfig,
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
|
@ -132,6 +133,11 @@ func NewClient(config Config) (*Client, error) {
|
|||
return nil, fmt.Errorf("Unknown network type: %s", config.NetWork)
|
||||
}
|
||||
|
||||
header := http.Header{}
|
||||
for k, v := range config.WebSocketHeaders {
|
||||
header.Add(k, v)
|
||||
}
|
||||
|
||||
host := net.JoinHostPort(config.HostName, config.Port)
|
||||
|
||||
var tlsConfig *tls.Config
|
||||
|
@ -144,6 +150,9 @@ func NewClient(config Config) (*Client, error) {
|
|||
if tlsConfig.ClientSessionCache == nil {
|
||||
tlsConfig.ClientSessionCache = getClientSessionCache()
|
||||
}
|
||||
if host := header.Get("Host"); host != "" {
|
||||
tlsConfig.ServerName = host
|
||||
}
|
||||
}
|
||||
|
||||
var wsConfig *WebsocketConfig
|
||||
|
@ -151,7 +160,7 @@ func NewClient(config Config) (*Client, error) {
|
|||
wsConfig = &WebsocketConfig{
|
||||
Host: host,
|
||||
Path: config.WebSocketPath,
|
||||
Headers: config.WebSocketHeaders,
|
||||
Headers: header,
|
||||
TLS: config.TLS,
|
||||
TLSConfig: tlsConfig,
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type websocketConn struct {
|
|||
type WebsocketConfig struct {
|
||||
Host string
|
||||
Path string
|
||||
Headers map[string]string
|
||||
Headers http.Header
|
||||
TLS bool
|
||||
TLSConfig *tls.Config
|
||||
}
|
||||
|
@ -131,14 +131,14 @@ func NewWebsocketConn(conn net.Conn, c *WebsocketConfig) (net.Conn, error) {
|
|||
|
||||
headers := http.Header{}
|
||||
if c.Headers != nil {
|
||||
for k, v := range c.Headers {
|
||||
headers.Set(k, v)
|
||||
for k := range c.Headers {
|
||||
headers.Add(k, c.Headers.Get(k))
|
||||
}
|
||||
}
|
||||
|
||||
wsConn, resp, err := dialer.Dial(uri.String(), headers)
|
||||
if err != nil {
|
||||
var reason string
|
||||
reason := err.Error()
|
||||
if resp != nil {
|
||||
reason = resp.Status
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user