func validateHTTPRouteMatchRequest()

in pkg/config/validation/virtualservice.go [140:224]


func validateHTTPRouteMatchRequest(http *networking.HTTPRoute, routeType HTTPRouteType) (errs error) {
	if routeType == IndependentRoute {
		for _, match := range http.Match {
			if match != nil {
				for name, header := range match.Headers {
					if header == nil {
						errs = appendErrors(errs, fmt.Errorf("header match %v cannot be null", name))
					}
					errs = appendErrors(errs, ValidateHTTPHeaderName(name))
					errs = appendErrors(errs, validateStringMatchRegexp(header, "headers"))
				}

				errs = appendErrors(errs, validateStringMatchRegexp(match.GetUri(), "uri"))
				errs = appendErrors(errs, validateStringMatchRegexp(match.GetScheme(), "scheme"))
				errs = appendErrors(errs, validateStringMatchRegexp(match.GetMethod(), "method"))
				errs = appendErrors(errs, validateStringMatchRegexp(match.GetAuthority(), "authority"))
				for _, qp := range match.GetQueryParams() {
					errs = appendErrors(errs, validateStringMatchRegexp(qp, "queryParams"))
				}
			}
		}
	} else {
		for _, match := range http.Match {
			if match != nil {
				if containRegexMatch(match.Uri) {
					errs = appendErrors(errs, errors.New("url match does not support regex match for delegating"))
				}
				if containRegexMatch(match.Scheme) {
					errs = appendErrors(errs, errors.New("scheme match does not support regex match for delegating"))
				}
				if containRegexMatch(match.Method) {
					errs = appendErrors(errs, errors.New("method match does not support regex match for delegating"))
				}
				if containRegexMatch(match.Authority) {
					errs = appendErrors(errs, errors.New("authority match does not support regex match for delegating"))
				}

				for name, header := range match.Headers {
					if header == nil {
						errs = appendErrors(errs, fmt.Errorf("header match %v cannot be null", name))
					}
					if containRegexMatch(header) {
						errs = appendErrors(errs, fmt.Errorf("header match %v does not support regex match for delegating", name))
					}
					errs = appendErrors(errs, ValidateHTTPHeaderName(name))
				}
				for name, param := range match.QueryParams {
					if param == nil {
						errs = appendErrors(errs, fmt.Errorf("query param match %v cannot be null", name))
					}
					if containRegexMatch(param) {
						errs = appendErrors(errs, fmt.Errorf("query param match %v does not support regex match for delegating", name))
					}
				}
				for name, header := range match.WithoutHeaders {
					if header == nil {
						errs = appendErrors(errs, fmt.Errorf("withoutHeaders match %v cannot be null", name))
					}
					if containRegexMatch(header) {
						errs = appendErrors(errs, fmt.Errorf("withoutHeaders match %v does not support regex match for delegating", name))
					}
					errs = appendErrors(errs, ValidateHTTPHeaderName(name))
				}

			}
		}
	}

	for _, match := range http.Match {
		if match != nil {
			if match.Port != 0 {
				errs = appendErrors(errs, ValidatePort(int(match.Port)))
			}
			errs = appendErrors(errs, labels.Instance(match.SourceLabels).Validate())
			errs = appendErrors(errs, validateGatewayNames(match.Gateways))
			if match.SourceNamespace != "" {
				if !labels.IsDNS1123Label(match.SourceNamespace) {
					errs = appendErrors(errs, fmt.Errorf("sourceNamespace match %s is invalid", match.SourceNamespace))
				}
			}
		}
	}

	return
}