|
50 | 50 | import io.grpc.xds.XdsClient.ResourceUpdate;
|
51 | 51 | import io.grpc.xds.XdsClientImpl.ResourceInvalidException;
|
52 | 52 | import io.grpc.xds.XdsRouteConfigureResource.RdsUpdate;
|
| 53 | +import io.grpc.xds.internal.MatcherParser; |
53 | 54 | import io.grpc.xds.internal.Matchers;
|
54 | 55 | import io.grpc.xds.internal.Matchers.FractionMatcher;
|
55 | 56 | import io.grpc.xds.internal.Matchers.HeaderMatcher;
|
@@ -392,39 +393,11 @@ private static StructOrError<FractionMatcher> parseFractionMatcher(FractionalPer
|
392 | 393 | @VisibleForTesting
|
393 | 394 | static StructOrError<HeaderMatcher> parseHeaderMatcher(
|
394 | 395 | io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto) {
|
395 |
| - switch (proto.getHeaderMatchSpecifierCase()) { |
396 |
| - case EXACT_MATCH: |
397 |
| - return StructOrError.fromStruct(HeaderMatcher.forExactValue( |
398 |
| - proto.getName(), proto.getExactMatch(), proto.getInvertMatch())); |
399 |
| - case SAFE_REGEX_MATCH: |
400 |
| - String rawPattern = proto.getSafeRegexMatch().getRegex(); |
401 |
| - Pattern safeRegExMatch; |
402 |
| - try { |
403 |
| - safeRegExMatch = Pattern.compile(rawPattern); |
404 |
| - } catch (PatternSyntaxException e) { |
405 |
| - return StructOrError.fromError( |
406 |
| - "HeaderMatcher [" + proto.getName() + "] contains malformed safe regex pattern: " |
407 |
| - + e.getMessage()); |
408 |
| - } |
409 |
| - return StructOrError.fromStruct(Matchers.HeaderMatcher.forSafeRegEx( |
410 |
| - proto.getName(), safeRegExMatch, proto.getInvertMatch())); |
411 |
| - case RANGE_MATCH: |
412 |
| - Matchers.HeaderMatcher.Range rangeMatch = Matchers.HeaderMatcher.Range.create( |
413 |
| - proto.getRangeMatch().getStart(), proto.getRangeMatch().getEnd()); |
414 |
| - return StructOrError.fromStruct(Matchers.HeaderMatcher.forRange( |
415 |
| - proto.getName(), rangeMatch, proto.getInvertMatch())); |
416 |
| - case PRESENT_MATCH: |
417 |
| - return StructOrError.fromStruct(Matchers.HeaderMatcher.forPresent( |
418 |
| - proto.getName(), proto.getPresentMatch(), proto.getInvertMatch())); |
419 |
| - case PREFIX_MATCH: |
420 |
| - return StructOrError.fromStruct(Matchers.HeaderMatcher.forPrefix( |
421 |
| - proto.getName(), proto.getPrefixMatch(), proto.getInvertMatch())); |
422 |
| - case SUFFIX_MATCH: |
423 |
| - return StructOrError.fromStruct(Matchers.HeaderMatcher.forSuffix( |
424 |
| - proto.getName(), proto.getSuffixMatch(), proto.getInvertMatch())); |
425 |
| - case HEADERMATCHSPECIFIER_NOT_SET: |
426 |
| - default: |
427 |
| - return StructOrError.fromError("Unknown header matcher type"); |
| 396 | + try { |
| 397 | + Matchers.HeaderMatcher headerMatcher = MatcherParser.parseHeaderMatcher(proto); |
| 398 | + return StructOrError.fromStruct(headerMatcher); |
| 399 | + } catch (IllegalArgumentException e) { |
| 400 | + return StructOrError.fromError(e.getMessage()); |
428 | 401 | }
|
429 | 402 | }
|
430 | 403 |
|
|
0 commit comments