Skip to content

Commit

Permalink
httproute: use lists insteads of maps for HTTPRequestHeaderFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
hbagdi committed May 25, 2021
1 parent 53e7802 commit 210b8b5
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 27 deletions.
21 changes: 19 additions & 2 deletions apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,23 @@ const (
HTTPRouteFilterExtensionRef HTTPRouteFilterType = "ExtensionRef"
)

// HTTPHeader represents an HTTP Header name and value as defined by RFC 7230.
type HTTPHeader struct {
// Name is the name of the HTTP query param to be matched. This must be an
// exact string match. (See
// https://tools.ietf.org/html/rfc7230#section-2.7.3).
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
Name string `json:"name"`

// Value is the value of HTTP query param to be matched.
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=1024
Value string `json:"value"`
}

// HTTPRequestHeaderFilter defines configuration for the RequestHeaderModifier
// filter.
type HTTPRequestHeaderFilter struct {
Expand All @@ -550,7 +567,7 @@ type HTTPRequestHeaderFilter struct {
// Support: Extended
//
// +optional
Set map[string]string `json:"set,omitempty"`
Set []HTTPHeader `json:"set,omitempty"`

// Add adds the given header (name, value) to the request
// before the action. It appends to any existing values associated
Expand All @@ -571,7 +588,7 @@ type HTTPRequestHeaderFilter struct {
// Support: Extended
//
// +optional
Add map[string]string `json:"add,omitempty"`
Add []HTTPHeader `json:"add,omitempty"`

// Remove the given header(s) from the HTTP request before the
// action. The value of RemoveHeader is a list of HTTP header
Expand Down
35 changes: 30 additions & 5 deletions apis/v1alpha2/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func TestValidateHTTPRoute(t *testing.T) {
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
Set: map[string]string{"special-header": "foo"},
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Value: "foo",
},
},
},
},
{
Expand All @@ -155,7 +160,12 @@ func TestValidateHTTPRoute(t *testing.T) {
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
Add: map[string]string{"my-header": "bar"},
Add: []gatewayv1a2.HTTPHeader{
{
Name: "my-header",
Value: "bar",
},
},
},
},
},
Expand Down Expand Up @@ -190,7 +200,12 @@ func TestValidateHTTPRoute(t *testing.T) {
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
Set: map[string]string{"special-header": "foo"},
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Value: "foo",
},
},
},
},
{
Expand All @@ -203,7 +218,12 @@ func TestValidateHTTPRoute(t *testing.T) {
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
Add: map[string]string{"my-header": "bar"},
Add: []gatewayv1a2.HTTPHeader{
{
Name: "my-header",
Value: "bar",
},
},
},
},
{
Expand Down Expand Up @@ -238,7 +258,12 @@ func TestValidateHTTPRoute(t *testing.T) {
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
Set: map[string]string{"special-header": "foo"},
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Value: "foo",
},
},
},
},
{
Expand Down
27 changes: 19 additions & 8 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 90 additions & 12 deletions config/crd/bases/networking.x-k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 210b8b5

Please sign in to comment.