ws和wss的path参数url解码后发送

http代理connect方法支持host参数自定义
Proxy-Agent修改为nginx
This commit is contained in:
wenyifan 2022-08-03 15:47:56 +08:00
parent 2e4aea5188
commit 6d72721cab
8 changed files with 40 additions and 12 deletions

View File

@ -222,6 +222,7 @@ type ConnectOptions struct {
UserAgent string
NoTLS bool
NoDelay bool
Host string
HeaderConfig map[string]string
}
@ -277,9 +278,16 @@ func NoDelayConnectOption(b bool) ConnectOption {
}
}
// HeaderConnectOption specifies the NoDelay option for ss.Connect.
// HeaderConnectOption specifies the Header option for ss.Connect.
func HeaderConnectOption(HeaderConfig map[string]string) ConnectOption {
return func(opts *ConnectOptions) {
opts.HeaderConfig = HeaderConfig
}
}
// HostConnectOption specifies the host for connect.
func HostConnectOption(host string) ConnectOption {
return func(opts *ConnectOptions) {
opts.Host = host
}
}

View File

@ -41,8 +41,8 @@ func init() {
flag.Parse()
if printVersion {
fmt.Fprintf(os.Stdout, "gost %s (%s %s/%s)\n",
gost.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Fprintf(os.Stdout, "gost %s (%s %s/%s)\nEnhanced:\n%s\n",
gost.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH, gost.Enhanced)
os.Exit(0)
}

View File

@ -301,6 +301,7 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
gost.NoTLSConnectOption(node.GetBool("notls")),
gost.NoDelayConnectOption(node.GetBool("nodelay")),
gost.HeaderConnectOption(headerCfg),
gost.HostConnectOption(node.Get("host")),
}
sshConfig := &gost.SSHConfig{}

View File

@ -20,7 +20,11 @@ import (
)
// Version is the gost version.
const Version = "2.11.2-EvanMod-v1.1"
const Version = "2.11.2-EvanMod-v1.2"
const Enhanced = "Add parameter sni for all tls\n" +
"Add parameter header=header.txt for custom header process\n" +
"Add parameter host for http connect"
const ProxyAgent = "nginx"
// Debug is a flag that enables the debug log.
var Debug bool

View File

@ -52,6 +52,10 @@ func (c *httpConnector) ConnectContext(ctx context.Context, conn net.Conn, netwo
ua = DefaultUserAgent
}
if opts.Host != "" {
address = opts.Host
}
conn.SetDeadline(time.Now().Add(timeout))
defer conn.SetDeadline(time.Time{})
@ -182,7 +186,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
ProtoMinor: 1,
Header: http.Header{},
}
resp.Header.Add("Proxy-Agent", "gost/"+Version)
resp.Header.Add("Proxy-Agent", ProxyAgent)
if !Can("tcp", host, h.options.Whitelist, h.options.Blacklist) {
log.Logf("[http] %s - %s : Unauthorized to tcp connect to %s",
@ -296,7 +300,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
if req.Method == http.MethodConnect {
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 {
log.Logf("[http] %s <- %s\n%s", conn.RemoteAddr(), conn.LocalAddr(), string(b))
}

View File

@ -372,7 +372,7 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
log.Logf("[http2] %s - %s\n%s", r.RemoteAddr, laddr, string(dump))
}
w.Header().Set("Proxy-Agent", "gost/"+Version)
w.Header().Set("Proxy-Agent", ProxyAgent)
if !Can("tcp", host, h.options.Whitelist, h.options.Blacklist) {
log.Logf("[http2] %s - %s : Unauthorized to tcp connect to %s",
@ -768,7 +768,7 @@ func (l *h2Listener) handleFunc(w http.ResponseWriter, r *http.Request) {
dump, _ := httputil.DumpRequest(r, false)
log.Log("[http2]", string(dump))
}
w.Header().Set("Proxy-Agent", "gost/"+Version)
w.Header().Set("Proxy-Agent", ProxyAgent)
conn, err := l.upgrade(w, r)
if err != nil {
log.Logf("[http2] %s - %s %s %s %s: %s",

2
strong_mod.sh Normal file
View File

@ -0,0 +1,2 @@
sed -b -i s/\*gost./*evan./g $1
sed -b -i s/]gost./]evan./g $1

17
ws.go
View File

@ -170,8 +170,13 @@ func (tr *mwsTransporter) initSession(addr string, conn net.Conn, opts *Handshak
if path == "" {
path = defaultWSPath
}
url := url.URL{Scheme: "ws", Host: opts.Host, Path: path}
conn, err := websocketClientConn(url.String(), conn, nil, wsOptions)
urlObj := url.URL{Scheme: "ws", Host: opts.Host, Path: path}
urlStr, errUnescape := url.QueryUnescape(urlObj.String())
if errUnescape != nil {
log.Logf("[ws] URL QueryUnescape Error URL.String() -> %s", urlObj.String())
}
conn, err := websocketClientConn(urlStr, conn, nil, wsOptions)
if err != nil {
return nil, err
}
@ -330,8 +335,12 @@ func (tr *mwssTransporter) initSession(addr string, conn net.Conn, opts *Handsha
if path == "" {
path = defaultWSPath
}
url := url.URL{Scheme: "wss", Host: opts.Host, Path: path}
conn, err := websocketClientConn(url.String(), conn, tlsConfig, wsOptions)
urlObj := url.URL{Scheme: "wss", Host: opts.Host, Path: path}
urlStr, errUnescape := url.QueryUnescape(urlObj.String())
if errUnescape != nil {
log.Logf("[ws] URL QueryUnescape Error URL.String() -> %s", urlObj.String())
}
conn, err := websocketClientConn(urlStr, conn, tlsConfig, wsOptions)
if err != nil {
return nil, err
}