diff --git a/cmd/gost/main.go b/cmd/gost/main.go index 43baaf2..cb32082 100644 --- a/cmd/gost/main.go +++ b/cmd/gost/main.go @@ -109,6 +109,7 @@ func initChain() (*gost.Chain, error) { wsOpts.EnableCompression = toBool(node.Values.Get("compression")) wsOpts.ReadBufferSize, _ = strconv.Atoi(node.Values.Get("rbuf")) wsOpts.WriteBufferSize, _ = strconv.Atoi(node.Values.Get("wbuf")) + wsOpts.UserAgent = node.Values.Get("agent") tr = gost.WSTransporter(wsOpts) case "wss": wsOpts := &gost.WSOptions{} diff --git a/gost.go b/gost.go index 83e665d..1ea576e 100644 --- a/gost.go +++ b/gost.go @@ -45,6 +45,7 @@ var ( var ( DefaultTLSConfig *tls.Config + DefaultUserAgent = "Chrome/60.0.3112.90" ) func init() { diff --git a/http.go b/http.go index bd01534..166e555 100644 --- a/http.go +++ b/http.go @@ -33,6 +33,7 @@ func (c *httpConnector) Connect(conn net.Conn, addr string) (net.Conn, error) { ProtoMinor: 1, Header: make(http.Header), } + req.Header.Set("User-Agent", DefaultUserAgent) req.Header.Set("Proxy-Connection", "keep-alive") if c.User != nil { diff --git a/ws.go b/ws.go index fb74845..69be7dc 100644 --- a/ws.go +++ b/ws.go @@ -19,6 +19,7 @@ type WSOptions struct { WriteBufferSize int HandshakeTimeout time.Duration EnableCompression bool + UserAgent string } type websocketConn struct { @@ -40,7 +41,12 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio return conn, nil }, } - c, resp, err := dialer.Dial(url, nil) + header := http.Header{} + header.Set("User-Agent", DefaultUserAgent) + if options.UserAgent != "" { + header.Set("User-Agent", options.UserAgent) + } + c, resp, err := dialer.Dial(url, header) if err != nil { return nil, err }