Cleanup vmessws

This commit is contained in:
世界 2022-08-26 10:22:20 +08:00
parent f841459004
commit 07a0381f8b
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 6 additions and 4 deletions

View file

@ -70,7 +70,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
} }
return nil, wrapDialError(response, err) return nil, wrapDialError(response, err)
} else { } else {
return &EarlyWebsocketConn{Client: c, create: make(chan struct{})}, nil return &EarlyWebsocketConn{Client: c, ctx: ctx, create: make(chan struct{})}, nil
} }
} }

View file

@ -1,6 +1,7 @@
package v2raywebsocket package v2raywebsocket
import ( import (
"context"
"encoding/base64" "encoding/base64"
"io" "io"
"net" "net"
@ -68,6 +69,7 @@ func (c *WebsocketConn) SetDeadline(t time.Time) error {
type EarlyWebsocketConn struct { type EarlyWebsocketConn struct {
*Client *Client
ctx context.Context
conn *WebsocketConn conn *WebsocketConn
create chan struct{} create chan struct{}
} }
@ -98,14 +100,14 @@ func (c *EarlyWebsocketConn) Write(b []byte) (n int, err error) {
if len(earlyData) > 0 { if len(earlyData) > 0 {
earlyDataString := base64.RawURLEncoding.EncodeToString(earlyData) earlyDataString := base64.RawURLEncoding.EncodeToString(earlyData)
if c.earlyDataHeaderName == "" { if c.earlyDataHeaderName == "" {
conn, response, err = c.dialer.Dial(c.uri+earlyDataString, c.headers) conn, response, err = c.dialer.DialContext(c.ctx, c.uri+earlyDataString, c.headers)
} else { } else {
headers := c.headers.Clone() headers := c.headers.Clone()
headers.Set(c.earlyDataHeaderName, earlyDataString) headers.Set(c.earlyDataHeaderName, earlyDataString)
conn, response, err = c.dialer.Dial(c.uri, headers) conn, response, err = c.dialer.DialContext(c.ctx, c.uri, headers)
} }
} else { } else {
conn, response, err = c.dialer.Dial(c.uri, c.headers) conn, response, err = c.dialer.DialContext(c.ctx, c.uri, c.headers)
} }
if err != nil { if err != nil {
return 0, wrapDialError(response, err) return 0, wrapDialError(response, err)