New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xds: support case insensitive path matching #7506
Merged
voidzcy
merged 3 commits into
grpc:master
from
voidzcy:impl/support_case_insensitive_path_match
Oct 15, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,10 +45,8 @@ final class RouteMatch { | |
this.headerMatchers = headerMatchers; | ||
} | ||
|
||
@VisibleForTesting | ||
RouteMatch(@Nullable String pathPrefixMatch, @Nullable String pathExactMatch) { | ||
this( | ||
new PathMatcher(pathExactMatch, pathPrefixMatch, null), | ||
static RouteMatch withPathExactOnly(String pathExact) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used for test only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
return new RouteMatch(PathMatcher.fromPath(pathExact, true), | ||
Collections.<HeaderMatcher>emptyList(), null); | ||
} | ||
|
||
|
@@ -82,19 +80,6 @@ boolean matches(String path, Map<String, Iterable<String>> headers) { | |
return fractionMatch == null || fractionMatch.matches(); | ||
} | ||
|
||
PathMatcher getPathMatch() { | ||
return pathMatch; | ||
} | ||
|
||
List<HeaderMatcher> getHeaderMatchers() { | ||
return Collections.unmodifiableList(headerMatchers); | ||
} | ||
|
||
@Nullable | ||
FractionMatcher getFractionMatch() { | ||
return fractionMatch; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
@@ -132,35 +117,37 @@ static final class PathMatcher { | |
private final String prefix; | ||
@Nullable | ||
private final Pattern regEx; | ||
private final boolean caseSensitive; | ||
|
||
PathMatcher(@Nullable String path, @Nullable String prefix, @Nullable Pattern regEx) { | ||
private PathMatcher(@Nullable String path, @Nullable String prefix, @Nullable Pattern regEx, | ||
boolean caseSensitive) { | ||
this.path = path; | ||
this.prefix = prefix; | ||
this.regEx = regEx; | ||
this.caseSensitive = caseSensitive; | ||
} | ||
|
||
private boolean matches(String fullMethodName) { | ||
if (path != null) { | ||
return path.equals(fullMethodName); | ||
} else if (prefix != null) { | ||
return fullMethodName.startsWith(prefix); | ||
} | ||
return regEx.matches(fullMethodName); | ||
static PathMatcher fromPath(String path, boolean caseSensitive) { | ||
return new PathMatcher(path, null, null, caseSensitive); | ||
} | ||
|
||
@Nullable | ||
String getPath() { | ||
return path; | ||
static PathMatcher fromPrefix(String prefix, boolean caseSensitive) { | ||
return new PathMatcher(null, prefix, null, caseSensitive); | ||
} | ||
|
||
@Nullable | ||
String getPrefix() { | ||
return prefix; | ||
static PathMatcher fromRegEx(Pattern regEx) { | ||
return new PathMatcher(null, null, regEx, false /* doesn't matter */); | ||
} | ||
|
||
@Nullable | ||
Pattern getRegEx() { | ||
return regEx; | ||
boolean matches(String fullMethodName) { | ||
if (path != null) { | ||
return caseSensitive ? path.equals(fullMethodName) : path.equalsIgnoreCase(fullMethodName); | ||
} else if (prefix != null) { | ||
return caseSensitive | ||
? fullMethodName.startsWith(prefix) | ||
: fullMethodName.toLowerCase().startsWith(prefix.toLowerCase()); | ||
} | ||
return regEx.matches(fullMethodName); | ||
} | ||
|
||
@Override | ||
|
@@ -174,25 +161,26 @@ public boolean equals(Object o) { | |
PathMatcher that = (PathMatcher) o; | ||
return Objects.equals(path, that.path) | ||
&& Objects.equals(prefix, that.prefix) | ||
&& Objects.equals(caseSensitive, that.caseSensitive) | ||
&& Objects.equals( | ||
regEx == null ? null : regEx.pattern(), | ||
that.regEx == null ? null : that.regEx.pattern()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(path, prefix, regEx == null ? null : regEx.pattern()); | ||
return Objects.hash(path, prefix, caseSensitive, regEx == null ? null : regEx.pattern()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringHelper toStringHelper = | ||
MoreObjects.toStringHelper(this); | ||
if (path != null) { | ||
toStringHelper.add("path", path); | ||
toStringHelper.add("path", path).add("caseSensitive", caseSensitive); | ||
} | ||
if (prefix != null) { | ||
toStringHelper.add("prefix", prefix); | ||
toStringHelper.add("prefix", prefix).add("caseSensitive", caseSensitive); | ||
} | ||
if (regEx != null) { | ||
toStringHelper.add("regEx", regEx.pattern()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be irrelevant change... This PR cleans up some
PathMatcher
/RouteMatch
APIs, which are used here. So I am just deleting this unused code.