Skip to content

Commit

Permalink
Issue jetty#8329 - use internal Map to keep compiled regex pattern fo…
Browse files Browse the repository at this point in the history
…r same hosts

Signed-off-by: Lukas Gisi <lukasgisi@gmail.com>
  • Loading branch information
sugilite committed Sep 24, 2023
1 parent e2430b5 commit f9a6d85
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
package org.eclipse.jetty.client;

import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -96,6 +98,7 @@ public abstract static class Proxy
// TODO use InetAddressSet? Or IncludeExcludeSet?
private final Set<String> included = new HashSet<>();
private final Set<String> excluded = new HashSet<>();
private final Map<String, Pattern> _exludedPatterns = new HashMap<>();
private final Origin origin;
private final SslContextFactory.Client sslContextFactory;

Expand Down Expand Up @@ -222,8 +225,13 @@ private boolean matchesWithWildcards(Origin.Address address, String pattern)
HostPort hostPort = new HostPort(pattern);
String host = hostPort.getHost();
int port = hostPort.getPort();
String hostRegex = extractHostRegex(host);
return Pattern.matches(hostRegex, address.getHost()) && (port <= 0 || port == address.getPort());
Pattern hostPattern = _exludedPatterns.computeIfAbsent(host, this::compileHostRegex);
return hostPattern.matcher(address.getHost()).matches() && (port <= 0 || port == address.getPort());
}

private Pattern compileHostRegex(String host)
{
return Pattern.compile(extractHostRegex(host));
}

private String extractHostRegex(String host)
Expand Down

0 comments on commit f9a6d85

Please sign in to comment.