Skip to content

Commit

Permalink
Support response header filter for GRPCRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed May 16, 2024
1 parent 9ca10f6 commit f0e75dc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
22 changes: 0 additions & 22 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,16 @@ func TestCreateServers(t *testing.T) {
Path: "@rule0-route0",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule0-route1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule0-route2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
Expand All @@ -672,7 +669,6 @@ func TestCreateServers(t *testing.T) {
Path: "@rule1-route0",
ProxyPass: "http://$test__route1_rule1$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/test/",
Expand All @@ -682,13 +678,11 @@ func TestCreateServers(t *testing.T) {
Path: "/path-only/",
ProxyPass: "http://invalid-backend-ref$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /path-only",
ProxyPass: "http://invalid-backend-ref$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/backend-tls-policy/",
Expand Down Expand Up @@ -756,21 +750,18 @@ func TestCreateServers(t *testing.T) {
Rewrites: []string{"^ /replacement break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /rewrite",
Rewrites: []string{"^ /replacement break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule8-route0",
Rewrites: []string{"^/rewrite-with-headers(.*)$ /prefix-replacement$1 break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/rewrite-with-headers/",
Expand Down Expand Up @@ -810,13 +801,11 @@ func TestCreateServers(t *testing.T) {
Path: "= /exact",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule12-route0",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /test",
Expand Down Expand Up @@ -1029,13 +1018,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "/coffee/",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /coffee",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1069,13 +1056,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "= /coffee",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/coffee/",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1119,13 +1104,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "/coffee/",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /coffee",
ProxyPass: "http://test_baz_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1244,13 +1227,11 @@ func TestCreateLocationsRootPath(t *testing.T) {
Path: "/path-1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/path-2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
Expand Down Expand Up @@ -1297,19 +1278,16 @@ func TestCreateLocationsRootPath(t *testing.T) {
Path: "/path-1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/path-2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions internal/mode/static/state/graph/grpcroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,15 @@ func validateGRPCFilter(
switch filter.Type {
case v1alpha2.GRPCRouteFilterRequestHeaderModifier:
return validateFilterHeaderModifier(validator, filter.RequestHeaderModifier, filterPath.Child(string(filter.Type)))
case v1alpha2.GRPCRouteFilterResponseHeaderModifier:
return validateFilterHeaderModifier(validator, filter.ResponseHeaderModifier, filterPath.Child(string(filter.Type)))
default:
valErr := field.NotSupported(
filterPath.Child("type"),
filter.Type,
[]string{
string(v1alpha2.GRPCRouteFilterRequestHeaderModifier),
string(v1alpha2.GRPCRouteFilterResponseHeaderModifier),
},
)
allErrs = append(allErrs, valErr)
Expand All @@ -277,6 +280,12 @@ func convertGRPCFilters(filters []v1alpha2.GRPCRouteFilter) []v1.HTTPRouteFilter
RequestHeaderModifier: filter.RequestHeaderModifier,
}
httpFilters = append(httpFilters, httpRequestHeaderFilter)
case v1alpha2.GRPCRouteFilterResponseHeaderModifier:
httpResponseHeaderFilter := v1.HTTPRouteFilter{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: filter.ResponseHeaderModifier,
}
httpFilters = append(httpFilters, httpResponseHeaderFilter)
default:
continue
}
Expand Down
30 changes: 29 additions & 1 deletion internal/mode/static/state/graph/grpcroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ func TestBuildGRPCRoute(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: "ResponseHeaderModifier",
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
}

grValidFilter := createGRPCRoute(
Expand All @@ -259,6 +267,14 @@ func TestBuildGRPCRoute(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
}

createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator {
Expand Down Expand Up @@ -580,7 +596,7 @@ func TestBuildGRPCRoute(t *testing.T) {
Conditions: []conditions.Condition{
staticConds.NewRouteUnsupportedValue(
`All rules are invalid: spec.rules[0].filters[0].type: ` +
`Unsupported value: "RequestMirror": supported values: "RequestHeaderModifier"`,
`Unsupported value: "RequestMirror": supported values: "RequestHeaderModifier", "ResponseHeaderModifier"`,
),
},
Spec: L7RouteSpec{
Expand Down Expand Up @@ -719,6 +735,14 @@ func TestConvertGRPCFilters(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: "ResponseHeaderModifier",
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
{
Type: "RequestMirror",
},
Expand All @@ -729,6 +753,10 @@ func TestConvertGRPCFilters(t *testing.T) {
Type: v1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: grFilters[0].RequestHeaderModifier,
},
{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: grFilters[1].ResponseHeaderModifier,
},
}

g := NewWithT(t)
Expand Down
5 changes: 3 additions & 2 deletions site/content/overview/gateway-api-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ See the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) comman
{{< bootstrap-table "table table-striped table-bordered" >}}
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
| --------- | ------------------- | ---------------------- | ------------------------------------- | ----------- |
| GRPCRoute | Partially Supported | Not supported | Not supported | v1alpha2 |
| GRPCRoute | Supported | Not supported | Not supported | v1alpha2 |
{{< /bootstrap-table >}}

**Fields**:
Expand All @@ -202,7 +202,8 @@ See the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) comman
- `filters`
- `type`: Supported.
- `requestHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.
- `responseHeaderModifier`, `requestMirror`, `extensionRef`: Not supported.
- `responseHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.
- `requestMirror`, `extensionRef`: Not supported.
- `backendRefs`: Partially supported. Backend ref `filters` are not supported.
- `status`
- `parents`
Expand Down

0 comments on commit f0e75dc

Please sign in to comment.