bzp2010 commented on code in PR #2570:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2570#discussion_r2370852842


##########
internal/adc/translator/httproute.go:
##########
@@ -797,3 +771,47 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match 
*gatewayv1.HTTPRouteMa
 
        return route, nil
 }
+
+func HeaderMatchToVars(matchType, name, value string) 
([]adctypes.StringOrSlice, error) {
+       name = strings.ToLower(name)
+       name = strings.ReplaceAll(name, "-", "_")
+
+       var this []adctypes.StringOrSlice
+       this = append(this, adctypes.StringOrSlice{
+               StrVal: "http_" + name,
+       })
+
+       switch matchType {
+       case string(gatewayv1.HeaderMatchExact):
+               this = append(this, adctypes.StringOrSlice{
+                       StrVal: "==",
+               })
+       case string(gatewayv1.HeaderMatchRegularExpression):
+               this = append(this, adctypes.StringOrSlice{
+                       StrVal: "~~",
+               })
+       default:
+               return nil, errors.New("unknown header match type " + matchType)
+       }
+
+       this = append(this, adctypes.StringOrSlice{
+               StrVal: value,
+       })
+       return this, nil
+}
+
+func (t *Translator) translateHTTPRouteHeaderMatchToVars(header 
gatewayv1.HTTPHeaderMatch) ([]adctypes.StringOrSlice, error) {
+       var matchType string
+       if header.Type != nil {
+               matchType = string(*header.Type)
+       }
+       return HeaderMatchToVars(matchType, string(header.Name), header.Value)
+}
+
+func (t *Translator) translateGRPCRouteHeaderMatchToVars(header 
gatewayv1.GRPCHeaderMatch) ([]adctypes.StringOrSlice, error) {
+       var matchType string
+       if header.Type != nil {
+               matchType = string(*header.Type)
+       }
+       return HeaderMatchToVars(matchType, string(header.Name), header.Value)
+}

Review Comment:
   Should it be in the grpcroute translator go file?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to