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) { ...@@ -109,6 +109,7 @@ func initChain() (*gost.Chain, error) {
wsOpts.EnableCompression = toBool(node.Values.Get("compression")) wsOpts.EnableCompression = toBool(node.Values.Get("compression"))
wsOpts.ReadBufferSize, _ = strconv.Atoi(node.Values.Get("rbuf")) wsOpts.ReadBufferSize, _ = strconv.Atoi(node.Values.Get("rbuf"))
wsOpts.WriteBufferSize, _ = strconv.Atoi(node.Values.Get("wbuf")) wsOpts.WriteBufferSize, _ = strconv.Atoi(node.Values.Get("wbuf"))
wsOpts.UserAgent = node.Values.Get("agent")
tr = gost.WSTransporter(wsOpts) tr = gost.WSTransporter(wsOpts)
case "wss": case "wss":
wsOpts := &gost.WSOptions{} wsOpts := &gost.WSOptions{}
......
...@@ -45,6 +45,7 @@ var ( ...@@ -45,6 +45,7 @@ var (
var ( var (
DefaultTLSConfig *tls.Config DefaultTLSConfig *tls.Config
DefaultUserAgent = "Chrome/60.0.3112.90"
) )
func init() { func init() {
......
...@@ -33,6 +33,7 @@ func (c *httpConnector) Connect(conn net.Conn, addr string) (net.Conn, error) { ...@@ -33,6 +33,7 @@ func (c *httpConnector) Connect(conn net.Conn, addr string) (net.Conn, error) {
ProtoMinor: 1, ProtoMinor: 1,
Header: make(http.Header), Header: make(http.Header),
} }
req.Header.Set("User-Agent", DefaultUserAgent)
req.Header.Set("Proxy-Connection", "keep-alive") req.Header.Set("Proxy-Connection", "keep-alive")
if c.User != nil { if c.User != nil {
......
...@@ -19,6 +19,7 @@ type WSOptions struct { ...@@ -19,6 +19,7 @@ type WSOptions struct {
WriteBufferSize int WriteBufferSize int
HandshakeTimeout time.Duration HandshakeTimeout time.Duration
EnableCompression bool EnableCompression bool
UserAgent string
} }
type websocketConn struct { type websocketConn struct {
...@@ -40,7 +41,12 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio ...@@ -40,7 +41,12 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio
return conn, nil 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 { if err != nil {
return nil, err 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