Sync inner fix (#634)

This commit is contained in:
澄潭
2023-11-14 11:15:26 +08:00
committed by GitHub
parent cb0479510f
commit 5174397e7c
14 changed files with 228 additions and 101 deletions

View File

@@ -15,6 +15,7 @@
package annotations
import (
"regexp"
"strings"
networking "istio.io/api/networking/v1alpha3"
@@ -37,6 +38,8 @@ const (
var (
_ Parser = headerControl{}
_ RouteHandler = headerControl{}
pattern = regexp.MustCompile(`\s+`)
)
type HeaderOperation struct {
@@ -138,6 +141,18 @@ func needHeaderControlConfig(annotations Annotations) bool {
annotations.HasHigress(responseHeaderRemove)
}
func trimQuotes(s string) string {
if len(s) >= 2 {
if s[0] == '"' && s[len(s)-1] == '"' {
return s[1 : len(s)-1]
}
if s[0] == '\'' && s[len(s)-1] == '\'' {
return s[1 : len(s)-1]
}
}
return s
}
func convertAddOrUpdate(headers string) map[string]string {
result := map[string]string{}
parts := strings.Split(headers, "\n")
@@ -147,13 +162,13 @@ func convertAddOrUpdate(headers string) map[string]string {
continue
}
keyValue := strings.Fields(part)
keyValue := pattern.Split(part, 2)
if len(keyValue) != 2 {
IngressLog.Errorf("Header format %s is invalid.", keyValue)
continue
}
key := strings.TrimSpace(keyValue[0])
value := strings.TrimSpace(keyValue[1])
key := trimQuotes(strings.TrimSpace(keyValue[0]))
value := trimQuotes(strings.TrimSpace(keyValue[1]))
result[key] = value
}
return result