Skip to content

Commit

Permalink
Fix UDP domain NAT
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai authored and hiddify-com committed Nov 13, 2023
1 parent c231aab commit 872cd2c
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions transport/v2raywebsocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
if !strings.HasPrefix(requestURL.Path, "/") {
requestURL.Path = "/" + requestURL.Path
}
if !strings.HasPrefix(requestURL.Path, "/") {
requestURL.Path = "/" + requestURL.Path
}
headers := make(http.Header)
for key, value := range options.Headers {
headers[key] = value
Expand All @@ -68,9 +65,6 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Go-http-client/1.1")
}
if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Go-http-client/1.1")
}
return &Client{
dialer,
tlsConfig,
Expand Down Expand Up @@ -107,31 +101,6 @@ func (c *Client) dialContext(ctx context.Context, requestURL *url.URL, headers h
return NewConn(conn, reader, nil, ws.StateClientSide), nil
}

func (c *Client) dialContext(ctx context.Context, requestURL *url.URL, headers http.Header) (*WebsocketConn, error) {
conn, err := c.dialer.DialContext(ctx, N.NetworkTCP, c.serverAddr)
if err != nil {
return nil, err
}
if c.tlsConfig != nil {
conn, err = tls.ClientHandshake(ctx, conn, c.tlsConfig)
if err != nil {
return nil, err
}
}
conn.SetDeadline(time.Now().Add(C.TCPTimeout))
var protocols []string
if protocolHeader := headers.Get("Sec-WebSocket-Protocol"); protocolHeader != "" {
protocols = []string{protocolHeader}
headers.Del("Sec-WebSocket-Protocol")
}
reader, _, err := ws.Dialer{Header: ws.HandshakeHeaderHTTP(headers), Protocols: protocols}.Upgrade(conn, requestURL)
conn.SetDeadline(time.Time{})
if err != nil {
return nil, err
}
return NewConn(conn, reader, nil, ws.StateClientSide), nil
}

func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
if c.maxEarlyData <= 0 {
conn, err := c.dialContext(ctx, &c.requestURL, c.headers)
Expand Down

0 comments on commit 872cd2c

Please sign in to comment.