add User-Agent header for http and ws
This commit is contained in:
parent
3862424269
commit
db589c63ba
@ -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{}
|
||||||
|
1
gost.go
1
gost.go
@ -45,6 +45,7 @@ var (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultTLSConfig *tls.Config
|
DefaultTLSConfig *tls.Config
|
||||||
|
DefaultUserAgent = "Chrome/60.0.3112.90"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
1
http.go
1
http.go
@ -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 {
|
||||||
|
8
ws.go
8
ws.go
@ -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
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user