mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
smarter port selection
This commit is contained in:
parent
fdab026a3b
commit
73dfc17a82
3 changed files with 20 additions and 1 deletions
BIN
bin/go-proxy
BIN
bin/go-proxy
Binary file not shown.
|
@ -42,6 +42,14 @@ var (
|
|||
}()
|
||||
)
|
||||
|
||||
var wellKnownHTTPPorts = map[uint16]bool{
|
||||
80: true,
|
||||
8000: true,
|
||||
8008: true, // alternative HTTP port
|
||||
8080: true,
|
||||
3000: true, // adguardhome, gogs, etc
|
||||
}
|
||||
|
||||
var (
|
||||
StreamSchemes = []string{StreamType_TCP, StreamType_UDP} // TODO: support "tcp:udp", "udp:tcp"
|
||||
HTTPSchemes = []string{"http", "https"}
|
||||
|
@ -92,6 +100,7 @@ var (
|
|||
Timeout: 5 * time.Second,
|
||||
KeepAlive: 5 * time.Second,
|
||||
}).DialContext,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -147,4 +156,4 @@ var logLevel = func() logrus.Level {
|
|||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
return logrus.GetLevel()
|
||||
}()
|
||||
}()
|
||||
|
|
|
@ -201,6 +201,11 @@ func selectPort(c *types.Container) uint16 {
|
|||
}
|
||||
|
||||
func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uint16 {
|
||||
for _, p := range c.Ports {
|
||||
if isWellKnownHTTPPort(p.PrivatePort) {
|
||||
return getPort(p)
|
||||
}
|
||||
}
|
||||
for _, p := range c.Ports {
|
||||
if port := getPort(p); port != 0 {
|
||||
return port
|
||||
|
@ -208,3 +213,8 @@ func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uin
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func isWellKnownHTTPPort(port uint16) bool {
|
||||
_, ok := wellKnownHTTPPorts[port]
|
||||
return ok
|
||||
}
|
Loading…
Add table
Reference in a new issue