mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-15 15:16:35 +08:00
反向代理设置中增加移除回源主机名端口功能
This commit is contained in:
@@ -25,3 +25,16 @@ func ListenReuseAddr(network string, addr string) (net.Listener, error) {
|
||||
}
|
||||
return config.Listen(context.Background(), network, addr)
|
||||
}
|
||||
|
||||
// ParseAddrHost 分析地址中的主机名部分
|
||||
func ParseAddrHost(addr string) string {
|
||||
if len(addr) == 0 {
|
||||
return addr
|
||||
}
|
||||
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return addr
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
14
internal/utils/net_test.go
Normal file
14
internal/utils/net_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseAddrHost(t *testing.T) {
|
||||
for _, addr := range []string{"a", "example.com", "example.com:1234", "::1", "[::1]", "[::1]:8080"} {
|
||||
t.Log(addr + " => " + utils.ParseAddrHost(addr))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user