@@ -111,6 +111,12 @@ func validateHTTPRouteFilters(filters []gatewayv1b1.HTTPRouteFilter, matches []g
111111 if filter .URLRewrite != nil && filter .URLRewrite .Path != nil {
112112 errs = append (errs , validateHTTPPathModifier (* filter .URLRewrite .Path , matches , path .Index (i ).Child ("urlRewrite" , "path" ))... )
113113 }
114+ if filter .RequestHeaderModifier != nil {
115+ errs = append (errs , validateHTTPHeaderModifier (* filter .RequestHeaderModifier , path .Index (i ).Child ("requestHeaderModifier" ))... )
116+ }
117+ if filter .ResponseHeaderModifier != nil {
118+ errs = append (errs , validateHTTPHeaderModifier (* filter .ResponseHeaderModifier , path .Index (i ).Child ("responseHeaderModifier" ))... )
119+ }
114120 errs = append (errs , validateHTTPRouteFilterTypeMatchesValue (filter , path .Index (i ))... )
115121 }
116122 // custom filters don't have any validation
@@ -276,6 +282,42 @@ func validateHTTPPathModifier(modifier gatewayv1b1.HTTPPathModifier, matches []g
276282 return errs
277283}
278284
285+ func validateHTTPHeaderModifier (filter gatewayv1b1.HTTPHeaderFilter , path * field.Path ) field.ErrorList {
286+ var errs field.ErrorList
287+ singleAction := make (map [string ]bool )
288+ for i , action := range filter .Add {
289+ if needsErr , ok := singleAction [string (action .Name )]; ok {
290+ if needsErr {
291+ errs = append (errs , field .Invalid (path .Child ("add" ), filter .Add [i ], "cannot specify multiple actions for header" ))
292+ }
293+ singleAction [string (action .Name )] = false
294+ } else {
295+ singleAction [string (action .Name )] = true
296+ }
297+ }
298+ for i , action := range filter .Set {
299+ if needsErr , ok := singleAction [string (action .Name )]; ok {
300+ if needsErr {
301+ errs = append (errs , field .Invalid (path .Child ("set" ), filter .Set [i ], "cannot specify multiple actions for header" ))
302+ }
303+ singleAction [string (action .Name )] = false
304+ } else {
305+ singleAction [string (action .Name )] = true
306+ }
307+ }
308+ for i , action := range filter .Remove {
309+ if needsErr , ok := singleAction [action ]; ok {
310+ if needsErr {
311+ errs = append (errs , field .Invalid (path .Child ("remove" ), filter .Remove [i ], "cannot specify multiple actions for header" ))
312+ }
313+ singleAction [action ] = false
314+ } else {
315+ singleAction [action ] = true
316+ }
317+ }
318+ return errs
319+ }
320+
279321func hasExactlyOnePrefixMatch (matches []gatewayv1b1.HTTPRouteMatch ) bool {
280322 if len (matches ) != 1 || matches [0 ].Path == nil {
281323 return false
0 commit comments