Commit db589c63 authored by rui.zheng's avatar rui.zheng

add User-Agent header for http and ws

parent 38624242
......@@ -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{}
......
......@@ -45,6 +45,7 @@ var (
var (
DefaultTLSConfig *tls.Config
DefaultUserAgent = "Chrome/60.0.3112.90"
)
func init() {
......
......@@ -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 {
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment