Feature: add v2ray-plugin

This commit is contained in:
Dreamacro
2019-02-11 15:25:10 +08:00
parent 53b5ef199f
commit 2383cca2ce
6 changed files with 332 additions and 44 deletions

View File

@@ -19,12 +19,12 @@ type websocketConn struct {
remoteAddr net.Addr
}
type websocketConfig struct {
host string
path string
headers map[string]string
tls bool
tlsConfig *tls.Config
type WebsocketConfig struct {
Host string
Path string
Headers map[string]string
TLS bool
TLSConfig *tls.Config
}
// Read implements net.Conn.Read()
@@ -102,7 +102,7 @@ func (wsc *websocketConn) SetWriteDeadline(t time.Time) error {
return wsc.conn.SetWriteDeadline(t)
}
func newWebsocketConn(conn net.Conn, c *websocketConfig) (net.Conn, error) {
func NewWebsocketConn(conn net.Conn, c *WebsocketConfig) (net.Conn, error) {
dialer := &websocket.Dialer{
NetDial: func(network, addr string) (net.Conn, error) {
return conn, nil
@@ -113,25 +113,25 @@ func newWebsocketConn(conn net.Conn, c *websocketConfig) (net.Conn, error) {
}
scheme := "ws"
if c.tls {
if c.TLS {
scheme = "wss"
dialer.TLSClientConfig = c.tlsConfig
dialer.TLSClientConfig = c.TLSConfig
}
host, port, _ := net.SplitHostPort(c.host)
host, port, _ := net.SplitHostPort(c.Host)
if (scheme == "ws" && port != "80") || (scheme == "wss" && port != "443") {
host = c.host
host = c.Host
}
uri := url.URL{
Scheme: scheme,
Host: host,
Path: c.path,
Path: c.Path,
}
headers := http.Header{}
if c.headers != nil {
for k, v := range c.headers {
if c.Headers != nil {
for k, v := range c.Headers {
headers.Set(k, v)
}
}