Skip to content

Commit

Permalink
disable wildcard in ignored hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Mar 9, 2024
1 parent 4450f96 commit 6def7a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ServerHandlersInit(Bootstrap clientBootstrap, Config config) throws KeySt

preForwardMatcher = createMatcherFromRules(config.preForwardRules());
postForwardMatcher = createMatcherFromRules(config.postForwardRules());
ignoredHostMatcher = new IterativeHostMatcher<>(List.of(Map.entry(config.ignoredHosts(), new Object())));
ignoredHostMatcher = new IterativeHostMatcher<>(List.of(Map.entry(config.ignoredHosts(), new Object())), false);
}

private <T extends ProcessingRule> IterativeHostMatcher<T> createMatcherFromRules(List<T> ruleList) {
Expand All @@ -56,7 +56,7 @@ private <T extends ProcessingRule> IterativeHostMatcher<T> createMatcherFromRule
}
rules.add(Map.entry(hostMatcher, rule));
}
return new IterativeHostMatcher<>(rules);
return new IterativeHostMatcher<>(rules, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public final class IterativeHostMatcher<T> {
private final Map<Pattern, List<T>> hostRegexes;
private final List<T> wildcards;

public IterativeHostMatcher(List<Map.Entry<HostMatcherConfig, T>> configs) {
public IterativeHostMatcher(List<Map.Entry<HostMatcherConfig, T>> configs, boolean allowWildcard) {
Map<String, List<T>> hosts = new HashMap<>();
Map<String, List<T>> parts = new HashMap<>();
Map<Pattern, List<T>> regexes = new HashMap<>();
List<T> wildcardElements = new ArrayList<>();
for(Map.Entry<HostMatcherConfig, T> entry : configs){
HostMatcherConfig config = entry.getKey();
T value = entry.getValue();
if(config.exact().isEmpty() && config.partial().isEmpty() && config.regex().isEmpty()){
if(allowWildcard && config.exact().isEmpty() && config.partial().isEmpty() && config.regex().isEmpty()){
wildcardElements.add(value);
}else{
addToMap(hosts, value, config.exact(), Function.identity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class HostMatcherTests {

private IterativeHostMatcher<Object> createMatcher(Set<String> exactHosts, Set<String> hostParts, Set<String> hostRegexes) {
return new IterativeHostMatcher<>(List.of(Map.entry(new HostMatcherConfig(exactHosts, hostParts, hostRegexes), new Object())));
return new IterativeHostMatcher<>(List.of(Map.entry(new HostMatcherConfig(exactHosts, hostParts, hostRegexes), new Object())), false);
}

@Test
Expand Down

0 comments on commit 6def7a7

Please sign in to comment.