Skip to content

Commit

Permalink
fix(MeshHttpRoute): don't split header value prematurely (#10191)
Browse files Browse the repository at this point in the history
Fixes #10156

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Co-authored-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
spacewander and lahabana committed May 14, 2024
1 parent 8c8ffe7 commit adc094d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ resources:
- appendAction: OVERWRITE_IF_EXISTS_OR_ADD
header:
key: request-set-header-multiple
value: one-value
- header:
key: request-set-header-multiple
value: second-value
value: one-value,second-value
- header:
key: request-add-header
value: add-value
Expand All @@ -62,10 +59,7 @@ resources:
- appendAction: OVERWRITE_IF_EXISTS_OR_ADD
header:
key: request-set-header-multiple
value: one-value
- header:
key: request-set-header-multiple
value: second-value
value: one-value,second-value
- header:
key: request-add-header
value: add-value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package filters

import (
"strings"

envoy_config_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"

common_api "github.com/kumahq/kuma/api/common/v1alpha1"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshhttproute/api/v1alpha1"
)

Expand All @@ -33,37 +30,25 @@ func headerModifiers(mod api.HeaderModifier) ([]*envoy_config_core.HeaderValueOp
var options []*envoy_config_core.HeaderValueOption

for _, set := range mod.Set {
for i, headerValue := range headerValues(set.Value) {
appendAction := envoy_config_core.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD
if i > 0 {
appendAction = envoy_config_core.HeaderValueOption_APPEND_IF_EXISTS_OR_ADD
}
replace := &envoy_config_core.HeaderValueOption{
AppendAction: appendAction,
Header: &envoy_config_core.HeaderValue{
Key: string(set.Name),
Value: headerValue,
},
}
options = append(options, replace)
replace := &envoy_config_core.HeaderValueOption{
AppendAction: envoy_config_core.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD,
Header: &envoy_config_core.HeaderValue{
Key: string(set.Name),
Value: string(set.Value),
},
}
options = append(options, replace)
}
for _, add := range mod.Add {
for _, headerValue := range headerValues(add.Value) {
appendOption := &envoy_config_core.HeaderValueOption{
AppendAction: envoy_config_core.HeaderValueOption_APPEND_IF_EXISTS_OR_ADD,
Header: &envoy_config_core.HeaderValue{
Key: string(add.Name),
Value: headerValue,
},
}
options = append(options, appendOption)
appendOption := &envoy_config_core.HeaderValueOption{
AppendAction: envoy_config_core.HeaderValueOption_APPEND_IF_EXISTS_OR_ADD,
Header: &envoy_config_core.HeaderValue{
Key: string(add.Name),
Value: string(add.Value),
},
}
options = append(options, appendOption)
}

return options, mod.Remove
}

func headerValues(raw common_api.HeaderValue) []string {
return strings.Split(string(raw), ",")
}

0 comments on commit adc094d

Please sign in to comment.