From c2c3f7284f430154599f03220cd381181e0fc126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 9 Nov 2023 15:58:23 +0800 Subject: [PATCH] Revert "Fix Host ignored in v2ray websocket transport" This reverts commit aaa67028637f8cd1055ac8ccc56b44d08dc4c546. --- transport/v2ray/transport.go | 2 +- transport/v2rayhttp/client.go | 2 +- transport/v2raywebsocket/client.go | 12 +++--------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/transport/v2ray/transport.go b/transport/v2ray/transport.go index 9dfee281..3481c852 100644 --- a/transport/v2ray/transport.go +++ b/transport/v2ray/transport.go @@ -50,7 +50,7 @@ func NewClientTransport(ctx context.Context, dialer N.Dialer, serverAddr M.Socks case C.V2RayTransportTypeGRPC: return NewGRPCClient(ctx, dialer, serverAddr, options.GRPCOptions, tlsConfig) case C.V2RayTransportTypeWebsocket: - return v2raywebsocket.NewClient(ctx, dialer, serverAddr, options.WebsocketOptions, tlsConfig) + return v2raywebsocket.NewClient(ctx, dialer, serverAddr, options.WebsocketOptions, tlsConfig), nil case C.V2RayTransportTypeQUIC: if tlsConfig == nil { return nil, C.ErrTLSRequired diff --git a/transport/v2rayhttp/client.go b/transport/v2rayhttp/client.go index f280eeef..d5e8a1f6 100644 --- a/transport/v2rayhttp/client.go +++ b/transport/v2rayhttp/client.go @@ -81,7 +81,7 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt uri.Path = options.Path err := sHTTP.URLSetPath(&uri, options.Path) if err != nil { - return nil, E.Cause(err, "parse path") + return nil, E.New("failed to set path: " + err.Error()) } client.url = &uri return client, nil diff --git a/transport/v2raywebsocket/client.go b/transport/v2raywebsocket/client.go index e7e857ca..9f14f676 100644 --- a/transport/v2raywebsocket/client.go +++ b/transport/v2raywebsocket/client.go @@ -28,7 +28,7 @@ type Client struct { earlyDataHeaderName string } -func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayWebsocketOptions, tlsConfig tls.Config) (adapter.V2RayClientTransport, error) { +func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayWebsocketOptions, tlsConfig tls.Config) adapter.V2RayClientTransport { wsDialer := &websocket.Dialer{ ReadBufferSize: 4 * 1024, WriteBufferSize: 4 * 1024, @@ -68,17 +68,11 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt requestURL.Path = options.Path err := sHTTP.URLSetPath(&requestURL, options.Path) if err != nil { - return nil, E.Cause(err, "parse path") + return nil } headers := make(http.Header) for key, value := range options.Headers { headers[key] = value - if key == "Host" { - if len(value) > 1 { - return nil, E.New("multiple Host headers") - } - requestURL.Host = value[0] - } } return &Client{ wsDialer, @@ -87,7 +81,7 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt headers, options.MaxEarlyData, options.EarlyDataHeaderName, - }, nil + } } func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {