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
ac554f67
Commit
ac554f67
authored
Aug 18, 2022
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add proxyAgent options for http/http2 handler
parent
b9e61dca
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
26 additions
and
6 deletions
+26
-6
README.md
README.md
+1
-1
README_en.md
README_en.md
+1
-1
cmd/gost/route.go
cmd/gost/route.go
+1
-0
gost.go
gost.go
+2
-0
handler.go
handler.go
+8
-0
http.go
http.go
+7
-2
http2.go
http2.go
+5
-1
selector.go
selector.go
+1
-1
No files found.
README.md
View file @
ac554f67
...
@@ -58,7 +58,7 @@ go build
...
@@ -58,7 +58,7 @@ go build
#### Docker
#### Docker
```
bash
```
bash
docker
pull ginuerzh/gost
docker
run
--rm
ginuerzh/gost
-V
```
```
#### Homebrew
#### Homebrew
...
...
README_en.md
View file @
ac554f67
...
@@ -53,7 +53,7 @@ go build
...
@@ -53,7 +53,7 @@ go build
#### Docker
#### Docker
```
bash
```
bash
docker
pull ginuerzh/gost
docker
run
--rm
ginuerzh/gost
-V
```
```
#### Homebrew
#### Homebrew
...
...
cmd/gost/route.go
View file @
ac554f67
...
@@ -664,6 +664,7 @@ func (r *route) GenRouters() ([]router, error) {
...
@@ -664,6 +664,7 @@ func (r *route) GenRouters() ([]router, error) {
gost
.
IPsHandlerOption
(
ips
),
gost
.
IPsHandlerOption
(
ips
),
gost
.
TCPModeHandlerOption
(
node
.
GetBool
(
"tcp"
)),
gost
.
TCPModeHandlerOption
(
node
.
GetBool
(
"tcp"
)),
gost
.
IPRoutesHandlerOption
(
tunRoutes
...
),
gost
.
IPRoutesHandlerOption
(
tunRoutes
...
),
gost
.
ProxyAgentHandlerOption
(
node
.
Get
(
"proxyAgent"
)),
)
)
rt
:=
router
{
rt
:=
router
{
...
...
gost.go
View file @
ac554f67
...
@@ -80,6 +80,8 @@ var (
...
@@ -80,6 +80,8 @@ var (
// DefaultUserAgent is the default HTTP User-Agent header used by HTTP and websocket.
// DefaultUserAgent is the default HTTP User-Agent header used by HTTP and websocket.
DefaultUserAgent
=
"Chrome/78.0.3904.106"
DefaultUserAgent
=
"Chrome/78.0.3904.106"
DefaultProxyAgent
=
"gost/"
+
Version
// DefaultMTU is the default mtu for tun/tap device
// DefaultMTU is the default mtu for tun/tap device
DefaultMTU
=
1350
DefaultMTU
=
1350
)
)
...
...
handler.go
View file @
ac554f67
...
@@ -42,6 +42,7 @@ type HandlerOptions struct {
...
@@ -42,6 +42,7 @@ type HandlerOptions struct {
IPs
[]
string
IPs
[]
string
TCPMode
bool
TCPMode
bool
IPRoutes
[]
IPRoute
IPRoutes
[]
IPRoute
ProxyAgent
string
}
}
// HandlerOption allows a common way to set handler options.
// HandlerOption allows a common way to set handler options.
...
@@ -211,6 +212,13 @@ func IPRoutesHandlerOption(routes ...IPRoute) HandlerOption {
...
@@ -211,6 +212,13 @@ func IPRoutesHandlerOption(routes ...IPRoute) HandlerOption {
}
}
}
}
// ProxyAgentHandlerOption sets the proxy agent for http handler.
func
ProxyAgentHandlerOption
(
agent
string
)
HandlerOption
{
return
func
(
opts
*
HandlerOptions
)
{
opts
.
ProxyAgent
=
agent
}
}
type
autoHandler
struct
{
type
autoHandler
struct
{
options
*
HandlerOptions
options
*
HandlerOptions
}
}
...
...
http.go
View file @
ac554f67
...
@@ -173,7 +173,12 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
...
@@ -173,7 +173,12 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
ProtoMinor
:
1
,
ProtoMinor
:
1
,
Header
:
http
.
Header
{},
Header
:
http
.
Header
{},
}
}
resp
.
Header
.
Add
(
"Proxy-Agent"
,
"gost/"
+
Version
)
proxyAgent
:=
DefaultProxyAgent
if
h
.
options
.
ProxyAgent
!=
""
{
proxyAgent
=
h
.
options
.
ProxyAgent
}
resp
.
Header
.
Add
(
"Proxy-Agent"
,
proxyAgent
)
if
!
Can
(
"tcp"
,
host
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
if
!
Can
(
"tcp"
,
host
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
log
.
Logf
(
"[http] %s - %s : Unauthorized to tcp connect to %s"
,
log
.
Logf
(
"[http] %s - %s : Unauthorized to tcp connect to %s"
,
...
@@ -287,7 +292,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
...
@@ -287,7 +292,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
if
req
.
Method
==
http
.
MethodConnect
{
if
req
.
Method
==
http
.
MethodConnect
{
b
:=
[]
byte
(
"HTTP/1.1 200 Connection established
\r\n
"
+
b
:=
[]
byte
(
"HTTP/1.1 200 Connection established
\r\n
"
+
"Proxy-Agent:
gost/"
+
Version
+
"
\r\n\r\n
"
)
"Proxy-Agent:
"
+
proxyAgent
+
"
\r\n\r\n
"
)
if
Debug
{
if
Debug
{
log
.
Logf
(
"[http] %s <- %s
\n
%s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
(),
string
(
b
))
log
.
Logf
(
"[http] %s <- %s
\n
%s"
,
conn
.
RemoteAddr
(),
conn
.
LocalAddr
(),
string
(
b
))
}
}
...
...
http2.go
View file @
ac554f67
...
@@ -365,7 +365,11 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
...
@@ -365,7 +365,11 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
log
.
Logf
(
"[http2] %s - %s
\n
%s"
,
r
.
RemoteAddr
,
laddr
,
string
(
dump
))
log
.
Logf
(
"[http2] %s - %s
\n
%s"
,
r
.
RemoteAddr
,
laddr
,
string
(
dump
))
}
}
w
.
Header
()
.
Set
(
"Proxy-Agent"
,
"gost/"
+
Version
)
proxyAgent
:=
DefaultProxyAgent
if
h
.
options
.
ProxyAgent
!=
""
{
proxyAgent
=
h
.
options
.
ProxyAgent
}
w
.
Header
()
.
Set
(
"Proxy-Agent"
,
proxyAgent
)
if
!
Can
(
"tcp"
,
host
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
if
!
Can
(
"tcp"
,
host
,
h
.
options
.
Whitelist
,
h
.
options
.
Blacklist
)
{
log
.
Logf
(
"[http2] %s - %s : Unauthorized to tcp connect to %s"
,
log
.
Logf
(
"[http2] %s - %s : Unauthorized to tcp connect to %s"
,
...
...
selector.go
View file @
ac554f67
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
var
(
var
(
// ErrNoneAvailable indicates there is no node available.
// ErrNoneAvailable indicates there is no node available.
ErrNoneAvailable
=
errors
.
New
(
"none available"
)
ErrNoneAvailable
=
errors
.
New
(
"none
node
available"
)
)
)
// NodeSelector as a mechanism to pick nodes and mark their status.
// NodeSelector as a mechanism to pick nodes and mark their status.
...
...
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