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


##########
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)
+}

Review Comment:
   Empty string is expected.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to