Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
e996e7c3
Commit
e996e7c3
authored
Jun 20, 2019
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add user-agent option for http/http2
parent
bea815ec
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
11 deletions
+33
-11
chain.go
chain.go
+3
-2
client.go
client.go
+12
-4
cmd/gost/route.go
cmd/gost/route.go
+4
-0
http.go
http.go
+5
-1
http2.go
http2.go
+5
-2
node.go
node.go
+4
-2
No files found.
chain.go
View file @
e996e7c3
...
...
@@ -150,7 +150,8 @@ func (c *Chain) dialWithOptions(addr string, options *ChainOptions) (net.Conn, e
return
nil
,
err
}
cc
,
err
:=
route
.
LastNode
()
.
Client
.
Connect
(
conn
,
ipAddr
,
AddrConnectOption
(
addr
))
cOpts
:=
append
([]
ConnectOption
{
AddrConnectOption
(
addr
)},
route
.
LastNode
()
.
ConnectOptions
...
)
cc
,
err
:=
route
.
LastNode
()
.
Client
.
Connect
(
conn
,
ipAddr
,
cOpts
...
)
if
err
!=
nil
{
conn
.
Close
()
return
nil
,
err
...
...
@@ -233,7 +234,7 @@ func (c *Chain) getConn() (conn net.Conn, err error) {
preNode
:=
node
for
_
,
node
:=
range
nodes
[
1
:
]
{
var
cc
net
.
Conn
cc
,
err
=
preNode
.
Client
.
Connect
(
cn
,
node
.
Addr
)
cc
,
err
=
preNode
.
Client
.
Connect
(
cn
,
node
.
Addr
,
preNode
.
ConnectOptions
...
)
if
err
!=
nil
{
cn
.
Close
()
node
.
MarkDead
()
...
...
client.go
View file @
e996e7c3
...
...
@@ -238,10 +238,11 @@ func QUICConfigHandshakeOption(config *QUICConfig) HandshakeOption {
// ConnectOptions describes the options for Connector.Connect.
type
ConnectOptions
struct
{
Addr
string
Timeout
time
.
Duration
User
*
url
.
Userinfo
Selector
gosocks5
.
Selector
Addr
string
Timeout
time
.
Duration
User
*
url
.
Userinfo
Selector
gosocks5
.
Selector
UserAgent
string
}
// ConnectOption allows a common way to set ConnectOptions.
...
...
@@ -274,3 +275,10 @@ func SelectorConnectOption(s gosocks5.Selector) ConnectOption {
opts
.
Selector
=
s
}
}
// UserAgentConnectOption specifies the HTTP user-agent header.
func
UserAgentConnectOption
(
ua
string
)
ConnectOption
{
return
func
(
opts
*
ConnectOptions
)
{
opts
.
UserAgent
=
ua
}
}
cmd/gost/route.go
View file @
e996e7c3
...
...
@@ -209,6 +209,10 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
gost
.
TimeoutDialOption
(
time
.
Duration
(
timeout
)
*
time
.
Second
),
)
node
.
ConnectOptions
=
[]
gost
.
ConnectOption
{
gost
.
UserAgentConnectOption
(
node
.
Get
(
"agent"
)),
}
if
host
==
""
{
host
=
node
.
Host
}
...
...
http.go
View file @
e996e7c3
...
...
@@ -37,6 +37,10 @@ func (c *httpConnector) Connect(conn net.Conn, addr string, options ...ConnectOp
if
timeout
<=
0
{
timeout
=
ConnectTimeout
}
ua
:=
opts
.
UserAgent
if
ua
==
""
{
ua
=
DefaultUserAgent
}
conn
.
SetDeadline
(
time
.
Now
()
.
Add
(
timeout
))
defer
conn
.
SetDeadline
(
time
.
Time
{})
...
...
@@ -49,7 +53,7 @@ func (c *httpConnector) Connect(conn net.Conn, addr string, options ...ConnectOp
ProtoMinor
:
1
,
Header
:
make
(
http
.
Header
),
}
req
.
Header
.
Set
(
"User-Agent"
,
DefaultUserAgent
)
req
.
Header
.
Set
(
"User-Agent"
,
ua
)
req
.
Header
.
Set
(
"Proxy-Connection"
,
"keep-alive"
)
user
:=
opts
.
User
...
...
http2.go
View file @
e996e7c3
...
...
@@ -38,6 +38,10 @@ func (c *http2Connector) Connect(conn net.Conn, addr string, options ...ConnectO
for
_
,
option
:=
range
options
{
option
(
opts
)
}
ua
:=
opts
.
UserAgent
if
ua
==
""
{
ua
=
DefaultUserAgent
}
cc
,
ok
:=
conn
.
(
*
http2ClientConn
)
if
!
ok
{
...
...
@@ -56,8 +60,7 @@ func (c *http2Connector) Connect(conn net.Conn, addr string, options ...ConnectO
Host
:
addr
,
ContentLength
:
-
1
,
}
// DEPRECATED
//req.Header.Set("Gost-Target", addr)
req
.
Header
.
Set
(
"User-Agent"
,
ua
)
user
:=
opts
.
User
if
user
==
nil
{
...
...
node.go
View file @
e996e7c3
...
...
@@ -28,6 +28,7 @@ type Node struct {
Values
url
.
Values
DialOptions
[]
DialOption
HandshakeOptions
[]
HandshakeOption
ConnectOptions
[]
ConnectOption
Client
*
Client
marker
*
failMarker
Bypass
*
Bypass
...
...
@@ -129,18 +130,19 @@ func (node *Node) Get(key string) string {
return
node
.
Values
.
Get
(
key
)
}
// GetBool
likes Get, but convert
parameter value to bool.
// GetBool
converts node
parameter value to bool.
func
(
node
*
Node
)
GetBool
(
key
string
)
bool
{
b
,
_
:=
strconv
.
ParseBool
(
node
.
Values
.
Get
(
key
))
return
b
}
// GetInt
likes Get, but convert
parameter value to int.
// GetInt
converts node
parameter value to int.
func
(
node
*
Node
)
GetInt
(
key
string
)
int
{
n
,
_
:=
strconv
.
Atoi
(
node
.
Values
.
Get
(
key
))
return
n
}
// GetDuration converts node parameter value to time.Duration.
func
(
node
*
Node
)
GetDuration
(
key
string
)
time
.
Duration
{
d
,
_
:=
time
.
ParseDuration
(
node
.
Values
.
Get
(
key
))
return
d
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment