mirror of
https://github.com/alibaba/higress.git
synced 2026-05-08 04:17:27 +08:00
Sync inner fix (#634)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user