Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResponseHeaderModifier to HTTPRouteFilter #1373

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/v1alpha2/grpcroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ type GRPCRouteFilter struct {
// Support: Core
//
// +optional
RequestHeaderModifier *HTTPRequestHeaderFilter `json:"requestHeaderModifier,omitempty"`
RequestHeaderModifier *HTTPHeaderFilter `json:"requestHeaderModifier,omitempty"`

// RequestMirror defines a schema for a filter that mirrors requests.
// Requests are sent to the specified destination, but responses from
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha2/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ const (
// +k8s:deepcopy-gen=false
type HTTPHeader = v1beta1.HTTPHeader

// HTTPRequestHeaderFilter defines configuration for the RequestHeaderModifier
// filter.
// HTTPHeaderFilter defines a filter that modifies the headers of an HTTP request
// or response.
// +k8s:deepcopy-gen=false
type HTTPRequestHeaderFilter = v1beta1.HTTPRequestHeaderFilter
type HTTPHeaderFilter = v1beta1.HTTPHeaderFilter

// HTTPPathModifierType defines the type of path redirect or rewrite.
// +k8s:deepcopy-gen=false
Expand Down
14 changes: 7 additions & 7 deletions apis/v1alpha2/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestValidateHTTPRoute(t *testing.T) {
Filters: []gatewayv1a2.HTTPRouteFilter{
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Expand All @@ -160,7 +160,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Add: []gatewayv1a2.HTTPHeader{
{
Name: "my-header",
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Expand All @@ -217,7 +217,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Add: []gatewayv1a2.HTTPHeader{
{
Name: "my-header",
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestValidateHTTPRoute(t *testing.T) {
Filters: []gatewayv1a2.HTTPRouteFilter{
{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Set: []gatewayv1a2.HTTPHeader{
{
Name: "special-header",
Expand Down Expand Up @@ -811,7 +811,7 @@ func TestValidateHTTPRouteTypeMatchesField(t *testing.T) {
name: "valid HTTPRouteFilterRequestHeaderModifier route filter",
routeFilter: gatewayv1a2.HTTPRouteFilter{
Type: gatewayv1a2.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{
Set: []gatewayv1a2.HTTPHeader{{Name: "name"}},
Add: []gatewayv1a2.HTTPHeader{{Name: "add"}},
Remove: []string{"remove"},
Expand Down Expand Up @@ -848,7 +848,7 @@ func TestValidateHTTPRouteTypeMatchesField(t *testing.T) {
name: "invalid HTTPRouteFilterRequestMirror type filter with non-matching field",
routeFilter: gatewayv1a2.HTTPRouteFilter{
Type: gatewayv1a2.HTTPRouteFilterRequestMirror,
RequestHeaderModifier: &gatewayv1a2.HTTPRequestHeaderFilter{},
RequestHeaderModifier: &gatewayv1a2.HTTPHeaderFilter{},
},
errCount: 2,
}, {
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha2/zz_generated.deepcopy.go

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

28 changes: 23 additions & 5 deletions apis/v1beta1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ type HTTPRouteFilter struct {
//
// +unionDiscriminator
// +kubebuilder:validation:Enum=RequestHeaderModifier;RequestMirror;RequestRedirect;ExtensionRef
// <gateway:experimental:validation:Enum=RequestHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef>
// <gateway:experimental:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef>
aryan9600 marked this conversation as resolved.
Show resolved Hide resolved
Type HTTPRouteFilterType `json:"type"`

// RequestHeaderModifier defines a schema for a filter that modifies request
Expand All @@ -581,7 +581,16 @@ type HTTPRouteFilter struct {
// Support: Core
//
// +optional
RequestHeaderModifier *HTTPRequestHeaderFilter `json:"requestHeaderModifier,omitempty"`
RequestHeaderModifier *HTTPHeaderFilter `json:"requestHeaderModifier,omitempty"`

// ResponseHeaderModifier defines a schema for a filter that modifies response
// headers.
//
// Support: Extended
//
// +optional
aryan9600 marked this conversation as resolved.
Show resolved Hide resolved
// <gateway:experimental>
ResponseHeaderModifier *HTTPHeaderFilter `json:"responseHeaderModifier,omitempty"`

// RequestMirror defines a schema for a filter that mirrors requests.
// Requests are sent to the specified destination, but responses from
Expand Down Expand Up @@ -631,6 +640,15 @@ const (
// Support in HTTPBackendRef: Extended
HTTPRouteFilterRequestHeaderModifier HTTPRouteFilterType = "RequestHeaderModifier"

// HTTPRouteFilterResponseHeaderModifier can be used to add or remove an HTTP
// header from an HTTP response before it is sent to the client.
//
// Support in HTTPRouteRule: Extended
//
// Support in HTTPBackendRef: Extended
// <gateway:experimental>
HTTPRouteFilterResponseHeaderModifier HTTPRouteFilterType = "ResponseHeaderModifier"
aryan9600 marked this conversation as resolved.
Show resolved Hide resolved

// HTTPRouteFilterRequestRedirect can be used to redirect a request to
// another location. This filter can also be used for HTTP to HTTPS
// redirects. This may not be used on the same Route rule or BackendRef as a
Expand Down Expand Up @@ -690,9 +708,9 @@ type HTTPHeader struct {
Value string `json:"value"`
}

// HTTPRequestHeaderFilter defines configuration for the RequestHeaderModifier
// filter.
type HTTPRequestHeaderFilter struct {
// HTTPHeaderFilter defines a filter that modifies the headers of an HTTP request
// or response.
type HTTPHeaderFilter struct {
// Set overwrites the request with the given header (name, value)
// before the action.
//
Expand Down
6 changes: 6 additions & 0 deletions apis/v1beta1/validation/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ func validateHTTPRouteFilterTypeMatchesValue(filter gatewayv1b1.HTTPRouteFilter,
if filter.RequestHeaderModifier == nil && filter.Type == gatewayv1b1.HTTPRouteFilterRequestHeaderModifier {
errs = append(errs, field.Required(path, "filter.RequestHeaderModifier must be specified for RequestHeaderModifier HTTPRouteFilter.Type"))
}
if filter.ResponseHeaderModifier != nil && filter.Type != gatewayv1b1.HTTPRouteFilterResponseHeaderModifier {
errs = append(errs, field.Invalid(path, filter.ResponseHeaderModifier, "must be nil if the HTTPRouteFilter.Type is not ResponseHeaderModifier"))
}
if filter.ResponseHeaderModifier == nil && filter.Type == gatewayv1b1.HTTPRouteFilterResponseHeaderModifier {
errs = append(errs, field.Required(path, "filter.ResponseHeaderModifier must be specified for ResponseHeaderModifier HTTPRouteFilter.Type"))
}
if filter.RequestMirror != nil && filter.Type != gatewayv1b1.HTTPRouteFilterRequestMirror {
errs = append(errs, field.Invalid(path, filter.RequestMirror, "must be nil if the HTTPRouteFilter.Type is not RequestMirror"))
}
Expand Down
38 changes: 30 additions & 8 deletions apis/v1beta1/validation/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestValidateHTTPRoute(t *testing.T) {
Filters: []gatewayv1b1.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{
{
Name: "special-header",
Expand All @@ -160,7 +160,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Add: []gatewayv1b1.HTTPHeader{
{
Name: "my-header",
Expand All @@ -174,7 +174,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
}, {
name: "invalid httpRoute with multiple duplicate filters",
errCount: 2,
errCount: 3,
rules: []gatewayv1b1.HTTPRouteRule{
{
Matches: []gatewayv1b1.HTTPRouteMatch{
Expand All @@ -197,7 +197,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{
{
Name: "special-header",
Expand All @@ -217,7 +217,7 @@ func TestValidateHTTPRoute(t *testing.T) {
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Add: []gatewayv1b1.HTTPHeader{
{
Name: "my-header",
Expand All @@ -226,6 +226,17 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Add: []gatewayv1b1.HTTPHeader{
{
Name: "extra-header",
Value: "foo",
},
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestMirror: &gatewayv1b1.HTTPRequestMirrorFilter{
Expand All @@ -235,6 +246,17 @@ func TestValidateHTTPRoute(t *testing.T) {
},
},
},
{
Type: gatewayv1b1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{
{
Name: "other-header",
Value: "bat",
},
},
},
},
},
},
},
Expand All @@ -254,7 +276,7 @@ func TestValidateHTTPRoute(t *testing.T) {
Filters: []gatewayv1b1.HTTPRouteFilter{
{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{
{
Name: "special-header",
Expand Down Expand Up @@ -811,7 +833,7 @@ func TestValidateHTTPRouteTypeMatchesField(t *testing.T) {
name: "valid HTTPRouteFilterRequestHeaderModifier route filter",
routeFilter: gatewayv1b1.HTTPRouteFilter{
Type: gatewayv1b1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{
Set: []gatewayv1b1.HTTPHeader{{Name: "name"}},
Add: []gatewayv1b1.HTTPHeader{{Name: "add"}},
Remove: []string{"remove"},
Expand Down Expand Up @@ -848,7 +870,7 @@ func TestValidateHTTPRouteTypeMatchesField(t *testing.T) {
name: "invalid HTTPRouteFilterRequestMirror type filter with non-matching field",
routeFilter: gatewayv1b1.HTTPRouteFilter{
Type: gatewayv1b1.HTTPRouteFilterRequestMirror,
RequestHeaderModifier: &gatewayv1b1.HTTPRequestHeaderFilter{},
RequestHeaderModifier: &gatewayv1b1.HTTPHeaderFilter{},
},
errCount: 2,
}, {
Expand Down
67 changes: 36 additions & 31 deletions apis/v1beta1/zz_generated.deepcopy.go

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

Loading