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.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{}
|
||||
|
1
gost.go
1
gost.go
@ -45,6 +45,7 @@ var (
|
||||
|
||||
var (
|
||||
DefaultTLSConfig *tls.Config
|
||||
DefaultUserAgent = "Chrome/60.0.3112.90"
|
||||
)
|
||||
|
||||
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,
|
||||
Header: make(http.Header),
|
||||
}
|
||||
req.Header.Set("User-Agent", DefaultUserAgent)
|
||||
req.Header.Set("Proxy-Connection", "keep-alive")
|
||||
|
||||
if c.User != nil {
|
||||
|
8
ws.go
8
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user