in pkg/providers/gateway/translation/gateway_httproute.go [282:375]
func (t *translator) translateGatewayHTTPRouteMatch(match *gatewayv1beta1.HTTPRouteMatch) (*apisixv1.Route, error) {
route := apisixv1.NewDefaultRoute()
if match.Path != nil {
switch *match.Path.Type {
case gatewayv1beta1.PathMatchExact:
route.Uri = *match.Path.Value
case gatewayv1beta1.PathMatchPathPrefix:
route.Uri = *match.Path.Value + "*"
case gatewayv1beta1.PathMatchRegularExpression:
var this []apisixv1.StringOrSlice
this = append(this, apisixv1.StringOrSlice{
StrVal: "uri",
})
this = append(this, apisixv1.StringOrSlice{
StrVal: "~~",
})
this = append(this, apisixv1.StringOrSlice{
StrVal: *match.Path.Value,
})
route.Vars = append(route.Vars, this)
default:
return nil, errors.New("unknown path match type " + string(*match.Path.Type))
}
}
if match.Headers != nil && len(match.Headers) > 0 {
for _, header := range match.Headers {
name := strings.ToLower(string(header.Name))
name = strings.ReplaceAll(name, "-", "_")
var this []apisixv1.StringOrSlice
this = append(this, apisixv1.StringOrSlice{
StrVal: "http_" + name,
})
switch *header.Type {
case gatewayv1beta1.HeaderMatchExact:
this = append(this, apisixv1.StringOrSlice{
StrVal: "==",
})
case gatewayv1beta1.HeaderMatchRegularExpression:
this = append(this, apisixv1.StringOrSlice{
StrVal: "~~",
})
default:
return nil, errors.New("unknown header match type " + string(*header.Type))
}
this = append(this, apisixv1.StringOrSlice{
StrVal: header.Value,
})
route.Vars = append(route.Vars, this)
}
}
if match.QueryParams != nil && len(match.QueryParams) > 0 {
for _, query := range match.QueryParams {
var this []apisixv1.StringOrSlice
this = append(this, apisixv1.StringOrSlice{
StrVal: "arg_" + strings.ToLower(query.Name),
})
switch *query.Type {
case gatewayv1beta1.QueryParamMatchExact:
this = append(this, apisixv1.StringOrSlice{
StrVal: "==",
})
case gatewayv1beta1.QueryParamMatchRegularExpression:
this = append(this, apisixv1.StringOrSlice{
StrVal: "~~",
})
default:
return nil, errors.New("unknown query match type " + string(*query.Type))
}
this = append(this, apisixv1.StringOrSlice{
StrVal: query.Value,
})
route.Vars = append(route.Vars, this)
}
}
if match.Method != nil {
route.Methods = []string{
string(*match.Method),
}
}
return route, nil
}