Skip to content

Commit

Permalink
fix: add header values as described in the documentation (envoyproxy#…
Browse files Browse the repository at this point in the history
…4031)

Add header values after splitting the provided value string on ',', like
described in the documentation.

Signed-off-by: Lior Okman <lior.okman@sap.com>
(cherry picked from commit eac30d6)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
liorokman authored and arkodg committed Sep 7, 2024
1 parent cbd14ed commit 3190cde
Show file tree
Hide file tree
Showing 21 changed files with 181 additions and 86 deletions.
8 changes: 4 additions & 4 deletions internal/gatewayapi/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (t *Translator) processRequestHeaderModifierFilter(
newHeader := ir.AddHeader{
Name: headerKey,
Append: true,
Value: addHeader.Value,
Value: strings.Split(addHeader.Value, ","),
}

filterContext.AddRequestHeaders = append(filterContext.AddRequestHeaders, newHeader)
Expand Down Expand Up @@ -500,7 +500,7 @@ func (t *Translator) processRequestHeaderModifierFilter(
newHeader := ir.AddHeader{
Name: string(setHeader.Name),
Append: false,
Value: setHeader.Value,
Value: strings.Split(setHeader.Value, ","),
}

filterContext.AddRequestHeaders = append(filterContext.AddRequestHeaders, newHeader)
Expand Down Expand Up @@ -617,7 +617,7 @@ func (t *Translator) processResponseHeaderModifierFilter(
newHeader := ir.AddHeader{
Name: headerKey,
Append: true,
Value: addHeader.Value,
Value: strings.Split(addHeader.Value, ","),
}

filterContext.AddResponseHeaders = append(filterContext.AddResponseHeaders, newHeader)
Expand Down Expand Up @@ -672,7 +672,7 @@ func (t *Translator) processResponseHeaderModifierFilter(
newHeader := ir.AddHeader{
Name: string(setHeader.Name),
Append: false,
Value: setHeader.Value,
Value: strings.Split(setHeader.Value, ","),
}

filterContext.AddResponseHeaders = append(filterContext.AddResponseHeaders, newHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ grpcRoutes:
sectionName: http
rules:
- filters:
- type: "RequestHeaderModifier"
requestHeaderModifier:
add:
- name: "my-header-multi-value"
value: "foo,bar"
- type: "RequestHeaderModifier"
requestHeaderModifier:
add:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ grpcRoutes:
- name: service-1
port: 8080
filters:
- requestHeaderModifier:
add:
- name: my-header-multi-value
value: foo,bar
type: RequestHeaderModifier
- requestHeaderModifier:
add:
- name: my-header
Expand Down Expand Up @@ -117,9 +122,15 @@ xdsIR:
port: 10080
routes:
- addRequestHeaders:
- append: true
name: my-header-multi-value
value:
- foo
- bar
- append: true
name: my-header
value: foo
value:
- foo
destination:
name: grpcroute/default/grpcroute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ xdsIR:
addRequestHeaders:
- append: false
name: add-header-3
value: some-value
value:
- some-value
protocol: HTTP
weight: 1
hostname: '*'
Expand All @@ -172,10 +173,12 @@ xdsIR:
addRequestHeaders:
- append: true
name: add-header-1
value: some-value
value:
- some-value
- append: true
name: add-header-2
value: some-value
value:
- some-value
protocol: HTTP
weight: 8
- addressType: IP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ xdsIR:
- addRequestHeaders:
- append: true
name: add-header-1
value: some-value
value:
- some-value
- append: true
name: add-header-2
value: some-value
value:
- some-value
- append: true
name: add-header-3
value: some-value
value:
- some-value
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,24 @@ xdsIR:
- addRequestHeaders:
- append: true
name: Set-Header-1
value: some-value
value:
- some-value
- append: true
name: set-header-2
value: some-value
value:
- some-value
- append: true
name: set-header-3
value: some-value
value:
- some-value
- append: true
name: set-header-5
value: some-value
value:
- some-value
- append: false
name: set-header-4
value: some-value
value:
- some-value
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ xdsIR:
- addRequestHeaders:
- append: true
name: example-header-2
value: ""
value:
- ""
- append: false
name: example-header-1
value: ""
value:
- ""
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ xdsIR:
- addRequestHeaders:
- append: true
name: X-Header-Add
value: header-val-1
value:
- header-val-1
- append: true
name: X-Header-Add-Append
value: header-val-2
value:
- header-val-2
- append: false
name: X-Header-Set
value: set-overwrites-values
value:
- set-overwrites-values
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,24 @@ xdsIR:
- addResponseHeaders:
- append: true
name: Set-Header-1
value: some-value
value:
- some-value
- append: true
name: set-header-2
value: some-value
value:
- some-value
- append: true
name: set-header-3
value: some-value
value:
- some-value
- append: true
name: set-header-5
value: some-value
value:
- some-value
- append: false
name: set-header-4
value: some-value
value:
- some-value
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ xdsIR:
- addResponseHeaders:
- append: true
name: add-header-1
value: some-value
value:
- some-value
- append: true
name: add-header-2
value: some-value
value:
- some-value
- append: true
name: add-header-3
value: some-value
value:
- some-value
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,24 @@ xdsIR:
- addResponseHeaders:
- append: true
name: Set-Header-1
value: some-value
value:
- some-value
- append: true
name: set-header-2
value: some-value
value:
- some-value
- append: true
name: set-header-3
value: some-value
value:
- some-value
- append: true
name: set-header-5
value: some-value
value:
- some-value
- append: false
name: set-header-4
value: some-value
value:
- some-value
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ xdsIR:
- addResponseHeaders:
- append: true
name: example-header-2
value: ""
value:
- ""
- append: false
name: example-header-1
value: ""
value:
- ""
destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand Down
6 changes: 3 additions & 3 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,9 +1178,9 @@ func NewDestEndpoint(host string, port uint32) *DestinationEndpoint {
// AddHeader configures a header to be added to a request or response.
// +k8s:deepcopy-gen=true
type AddHeader struct {
Name string `json:"name" yaml:"name"`
Value string `json:"value" yaml:"value"`
Append bool `json:"append" yaml:"append"`
Name string `json:"name" yaml:"name"`
Value []string `json:"value" yaml:"value"`
Append bool `json:"append" yaml:"append"`
}

// Validate the fields within the AddHeader structure
Expand Down
22 changes: 10 additions & 12 deletions internal/ir/xds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,16 @@ var (
AddRequestHeaders: []AddHeader{
{
Name: "example-header",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
{
Name: "example-header-2",
Value: "example-value-2",
Value: []string{"example-value-2"},
Append: false,
},
{
Name: "empty-header",
Value: "",
Append: false,
},
},
Expand Down Expand Up @@ -376,12 +375,12 @@ var (
AddRequestHeaders: []AddHeader{
{
Name: "example-header",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
{
Name: "example-header",
Value: "example-value-2",
Value: []string{"example-value-2"},
Append: false,
},
},
Expand All @@ -401,7 +400,7 @@ var (
AddRequestHeaders: []AddHeader{
{
Name: "",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
},
Expand All @@ -416,17 +415,16 @@ var (
AddResponseHeaders: []AddHeader{
{
Name: "example-header",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
{
Name: "example-header-2",
Value: "example-value-2",
Value: []string{"example-value-2"},
Append: false,
},
{
Name: "empty-header",
Value: "",
Append: false,
},
},
Expand Down Expand Up @@ -454,12 +452,12 @@ var (
AddResponseHeaders: []AddHeader{
{
Name: "example-header",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
{
Name: "example-header",
Value: "example-value-2",
Value: []string{"example-value-2"},
Append: false,
},
},
Expand All @@ -479,7 +477,7 @@ var (
AddResponseHeaders: []AddHeader{
{
Name: "",
Value: "example-value",
Value: []string{"example-value"},
Append: true,
},
},
Expand Down
Loading

0 comments on commit 3190cde

Please sign in to comment.