mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +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 (
|
var (
|
||||||
StreamSchemes = []string{StreamType_TCP, StreamType_UDP} // TODO: support "tcp:udp", "udp:tcp"
|
StreamSchemes = []string{StreamType_TCP, StreamType_UDP} // TODO: support "tcp:udp", "udp:tcp"
|
||||||
HTTPSchemes = []string{"http", "https"}
|
HTTPSchemes = []string{"http", "https"}
|
||||||
|
@ -92,6 +100,7 @@ var (
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
KeepAlive: 5 * time.Second,
|
KeepAlive: 5 * time.Second,
|
||||||
}).DialContext,
|
}).DialContext,
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -147,4 +156,4 @@ var logLevel = func() logrus.Level {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
return logrus.GetLevel()
|
return logrus.GetLevel()
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -201,6 +201,11 @@ func selectPort(c *types.Container) uint16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) 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 {
|
for _, p := range c.Ports {
|
||||||
if port := getPort(p); port != 0 {
|
if port := getPort(p); port != 0 {
|
||||||
return port
|
return port
|
||||||
|
@ -208,3 +213,8 @@ func selectPortInternal(c *types.Container, getPort func(types.Port) uint16) uin
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isWellKnownHTTPPort(port uint16) bool {
|
||||||
|
_, ok := wellKnownHTTPPorts[port]
|
||||||
|
return ok
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue