Skip to content

Commit

Permalink
Issue jetty#8329 - use internal Map to keep parsed HostPorts for same…
Browse files Browse the repository at this point in the history
… patterns

Signed-off-by: Lukas Gisi <lukasgisi@gmail.com>
  • Loading branch information
sugilite committed Sep 24, 2023
1 parent f9a6d85 commit 946bbf7
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public abstract static class Proxy
private final Set<String> included = new HashSet<>();
private final Set<String> excluded = new HashSet<>();
private final Map<String, Pattern> _exludedPatterns = new HashMap<>();
private final Map<String, HostPort> _hostPorts = new HashMap<>();
private final Origin origin;
private final SslContextFactory.Client sslContextFactory;

Expand Down Expand Up @@ -214,15 +215,15 @@ public boolean matches(Origin origin)
private boolean matches(Origin.Address address, String pattern)
{
// TODO: add support for CIDR notation like 192.168.0.0/24, see DoSFilter
HostPort hostPort = new HostPort(pattern);
HostPort hostPort = _hostPorts.computeIfAbsent(pattern, HostPort::new);
String host = hostPort.getHost();
int port = hostPort.getPort();
return host.equals(address.getHost()) && (port <= 0 || port == address.getPort());
}

private boolean matchesWithWildcards(Origin.Address address, String pattern)
{
HostPort hostPort = new HostPort(pattern);
HostPort hostPort = _hostPorts.computeIfAbsent(pattern, HostPort::new);
String host = hostPort.getHost();
int port = hostPort.getPort();
Pattern hostPattern = _exludedPatterns.computeIfAbsent(host, this::compileHostRegex);
Expand Down

0 comments on commit 946bbf7

Please sign in to comment.