6
6
"strings"
7
7
gotemplate "text/template"
8
8
9
- "sigs.k8s.io/gateway-api/apis/v1beta1"
10
-
11
9
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http"
12
10
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane"
13
11
)
@@ -89,11 +87,9 @@ func createLocations(pathRules []dataplane.PathRule, listenerPort int32) []http.
89
87
extLocations := initializeExternalLocations (rule , pathsAndTypes )
90
88
91
89
for matchRuleIdx , r := range rule .MatchRules {
92
- m := r .GetMatch ()
93
-
94
90
buildLocations := extLocations
95
- if len (rule .MatchRules ) != 1 || ! isPathOnlyMatch (m ) {
96
- intLocation , match := initializeInternalLocation (rule , matchRuleIdx , m )
91
+ if len (rule .MatchRules ) != 1 || ! isPathOnlyMatch (r . Match ) {
92
+ intLocation , match := initializeInternalLocation (rule , matchRuleIdx , r . Match )
97
93
buildLocations = []http.Location {intLocation }
98
94
matches = append (matches , match )
99
95
}
@@ -228,20 +224,20 @@ func initializeExternalLocations(
228
224
func initializeInternalLocation (
229
225
rule dataplane.PathRule ,
230
226
matchRuleIdx int ,
231
- match v1beta1. HTTPRouteMatch ,
227
+ match dataplane. Match ,
232
228
) (http.Location , httpMatch ) {
233
229
path := createPathForMatch (rule .Path , rule .PathType , matchRuleIdx )
234
230
return createMatchLocation (path ), createHTTPMatch (match , path )
235
231
}
236
232
237
- func createReturnValForRedirectFilter (filter * v1beta1 .HTTPRequestRedirectFilter , listenerPort int32 ) * http.Return {
233
+ func createReturnValForRedirectFilter (filter * dataplane .HTTPRequestRedirectFilter , listenerPort int32 ) * http.Return {
238
234
if filter == nil {
239
235
return nil
240
236
}
241
237
242
238
hostname := "$host"
243
239
if filter .Hostname != nil {
244
- hostname = string ( * filter .Hostname )
240
+ hostname = * filter .Hostname
245
241
}
246
242
247
243
code := http .StatusFound
@@ -251,7 +247,7 @@ func createReturnValForRedirectFilter(filter *v1beta1.HTTPRequestRedirectFilter,
251
247
252
248
port := listenerPort
253
249
if filter .Port != nil {
254
- port = int32 ( * filter .Port )
250
+ port = * filter .Port
255
251
}
256
252
257
253
hostnamePort := fmt .Sprintf ("%s:%d" , hostname , port )
@@ -286,7 +282,7 @@ func createReturnValForRedirectFilter(filter *v1beta1.HTTPRequestRedirectFilter,
286
282
// If the request satisfies the httpMatch, NGINX will redirect the request to the location RedirectPath.
287
283
type httpMatch struct {
288
284
// Method is the HTTPMethod of the HTTPRouteMatch.
289
- Method v1beta1. HTTPMethod `json:"method,omitempty"`
285
+ Method string `json:"method,omitempty"`
290
286
// RedirectPath is the path to redirect the request to if the request satisfies the match conditions.
291
287
RedirectPath string `json:"redirectPath,omitempty"`
292
288
// Headers is a list of HTTPHeaders name value pairs with the format "{name}:{value}".
@@ -297,7 +293,7 @@ type httpMatch struct {
297
293
Any bool `json:"any,omitempty"`
298
294
}
299
295
300
- func createHTTPMatch (match v1beta1. HTTPRouteMatch , redirectPath string ) httpMatch {
296
+ func createHTTPMatch (match dataplane. Match , redirectPath string ) httpMatch {
301
297
hm := httpMatch {
302
298
RedirectPath : redirectPath ,
303
299
}
@@ -316,14 +312,12 @@ func createHTTPMatch(match v1beta1.HTTPRouteMatch, redirectPath string) httpMatc
316
312
headerNames := make (map [string ]struct {})
317
313
318
314
for _ , h := range match .Headers {
319
- if * h .Type == v1beta1 .HeaderMatchExact {
320
- // duplicate header names are not permitted by the spec
321
- // only configure the first entry for every header name (case-insensitive)
322
- lowerName := strings .ToLower (string (h .Name ))
323
- if _ , ok := headerNames [lowerName ]; ! ok {
324
- headers = append (headers , createHeaderKeyValString (h ))
325
- headerNames [lowerName ] = struct {}{}
326
- }
315
+ // duplicate header names are not permitted by the spec
316
+ // only configure the first entry for every header name (case-insensitive)
317
+ lowerName := strings .ToLower (h .Name )
318
+ if _ , ok := headerNames [lowerName ]; ! ok {
319
+ headers = append (headers , createHeaderKeyValString (h ))
320
+ headerNames [lowerName ] = struct {}{}
327
321
}
328
322
}
329
323
hm .Headers = headers
@@ -333,9 +327,7 @@ func createHTTPMatch(match v1beta1.HTTPRouteMatch, redirectPath string) httpMatc
333
327
params := make ([]string , 0 , len (match .QueryParams ))
334
328
335
329
for _ , p := range match .QueryParams {
336
- if * p .Type == v1beta1 .QueryParamMatchExact {
337
- params = append (params , createQueryParamKeyValString (p ))
338
- }
330
+ params = append (params , createQueryParamKeyValString (p ))
339
331
}
340
332
hm .QueryParams = params
341
333
}
@@ -345,7 +337,7 @@ func createHTTPMatch(match v1beta1.HTTPRouteMatch, redirectPath string) httpMatc
345
337
346
338
// The name and values are delimited by "=". A name and value can always be recovered using strings.SplitN(arg,"=", 2).
347
339
// Query Parameters are case-sensitive so case is preserved.
348
- func createQueryParamKeyValString (p v1beta1 .HTTPQueryParamMatch ) string {
340
+ func createQueryParamKeyValString (p dataplane .HTTPQueryParamMatch ) string {
349
341
return string (p .Name ) + "=" + p .Value
350
342
}
351
343
@@ -354,12 +346,12 @@ func createQueryParamKeyValString(p v1beta1.HTTPQueryParamMatch) string {
354
346
// Ex. foo:bar == FOO:bar, but foo:bar != foo:BAR,
355
347
// We preserve the case of the name here because NGINX allows us to look up the header names in a case-insensitive
356
348
// manner.
357
- func createHeaderKeyValString (h v1beta1 .HTTPHeaderMatch ) string {
349
+ func createHeaderKeyValString (h dataplane .HTTPHeaderMatch ) string {
358
350
return string (h .Name ) + HeaderMatchSeparator + h .Value
359
351
}
360
352
361
- func isPathOnlyMatch (match v1beta1. HTTPRouteMatch ) bool {
362
- return match .Method == nil && match .Headers == nil && match .QueryParams == nil
353
+ func isPathOnlyMatch (match dataplane. Match ) bool {
354
+ return match .Method == nil && len ( match .Headers ) == 0 && len ( match .QueryParams ) == 0
363
355
}
364
356
365
357
func createProxyPass (backendGroup dataplane.BackendGroup ) string {
0 commit comments