feat: support enbale nginx debug_connection (#8637)

This commit is contained in:
zou rui 2022-06-10 19:01:46 +08:00 committed by GitHub
parent 0005c080da
commit 2852e2998c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 0 deletions

View file

@ -65,6 +65,7 @@ const (
globalAuthAlwaysSetCookie = "global-auth-always-set-cookie"
luaSharedDictsKey = "lua-shared-dicts"
plugins = "plugins"
debugConnections = "debug-connections"
)
var (
@ -111,6 +112,7 @@ func ReadConfig(src map[string]string) config.Configuration {
blockRefererList := make([]string, 0)
responseHeaders := make([]string, 0)
luaSharedDicts := make(map[string]int)
debugConnectionsList := make([]string, 0)
//parse lua shared dict values
if val, ok := conf[luaSharedDictsKey]; ok {
@ -373,6 +375,24 @@ func ReadConfig(src map[string]string) config.Configuration {
delete(conf, plugins)
}
if val, ok := conf[debugConnections]; ok {
delete(conf, debugConnections)
for _, i := range splitAndTrimSpace(val, ",") {
validIp := net.ParseIP(i)
if validIp != nil {
debugConnectionsList = append(debugConnectionsList, i)
} else {
_, _, err := net.ParseCIDR(i)
if err == nil {
debugConnectionsList = append(debugConnectionsList, i)
} else {
klog.Warningf("%v is not a valid IP or CIDR address", i)
}
}
}
to.DebugConnections = debugConnectionsList
}
to.CustomHTTPErrors = filterErrors(errors)
to.SkipAccessLogURLs = skipUrls
to.WhitelistSourceRange = whiteList

View file

@ -75,6 +75,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
"proxy-add-original-uri-header": "false",
"disable-ipv6-dns": "true",
"default-type": "text/plain",
"debug-connections": "127.0.0.1,1.1.1.1/24,::1",
}
def := config.NewDefault()
def.CustomHTTPErrors = []int{300, 400}
@ -99,6 +100,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.LuaSharedDicts = defaultLuaSharedDicts
def.DisableIpv6DNS = true
def.DefaultType = "text/plain"
def.DebugConnections = []string{"127.0.0.1", "1.1.1.1/24", "::1"}
hash, err := hashstructure.Hash(def, &hashstructure.HashOptions{
TagName: "json",