From a23c751d5aa1c98c4b41c26eddfb96682f3809ae Mon Sep 17 00:00:00 2001 From: danthe1st Date: Fri, 8 Mar 2024 19:44:43 +0100 Subject: [PATCH] only initialize ignored hosts matcher once --- .../httpsintercept/handler/ServerHandlersInit.java | 6 ++++-- .../httpsintercept/handler/sni/CustomSniHandler.java | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/danthe1st/httpsintercept/handler/ServerHandlersInit.java b/src/main/java/io/github/danthe1st/httpsintercept/handler/ServerHandlersInit.java index cab4658..5c84c3c 100644 --- a/src/main/java/io/github/danthe1st/httpsintercept/handler/ServerHandlersInit.java +++ b/src/main/java/io/github/danthe1st/httpsintercept/handler/ServerHandlersInit.java @@ -33,7 +33,8 @@ public class ServerHandlersInit extends ChannelInitializer { private final SNIHandlerMapping sniMapping; private final Config config; - private IterativeHostMatcher preForwardMatcher; + private final IterativeHostMatcher preForwardMatcher; + private final IterativeHostMatcher ignoredHostMatcher; public ServerHandlersInit(Bootstrap clientBootstrap, Config config) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException { this.clientBootstrapTemplate = clientBootstrap; @@ -50,11 +51,12 @@ public ServerHandlersInit(Bootstrap clientBootstrap, Config config) throws KeySt rules.add(Map.entry(hostMatcher, preForwardRule)); } preForwardMatcher = new IterativeHostMatcher<>(rules); + ignoredHostMatcher = new IterativeHostMatcher<>(List.of(Map.entry(config.ignoredHosts(), new Object()))); } @Override protected void initChannel(SocketChannel socketChannel) throws Exception { - SniHandler sniHandler = new CustomSniHandler(sniMapping, clientBootstrapTemplate, config); + SniHandler sniHandler = new CustomSniHandler(sniMapping, clientBootstrapTemplate, ignoredHostMatcher); socketChannel.pipeline().addLast( sniHandler, new HttpServerCodec(), diff --git a/src/main/java/io/github/danthe1st/httpsintercept/handler/sni/CustomSniHandler.java b/src/main/java/io/github/danthe1st/httpsintercept/handler/sni/CustomSniHandler.java index 5684d6f..93bbc37 100644 --- a/src/main/java/io/github/danthe1st/httpsintercept/handler/sni/CustomSniHandler.java +++ b/src/main/java/io/github/danthe1st/httpsintercept/handler/sni/CustomSniHandler.java @@ -2,10 +2,8 @@ import java.io.IOException; import java.util.Iterator; -import java.util.List; import java.util.Map; -import io.github.danthe1st.httpsintercept.config.Config; import io.github.danthe1st.httpsintercept.handler.raw.RawForwardIncomingRequestHandler; import io.github.danthe1st.httpsintercept.matcher.IterativeHostMatcher; import io.netty.bootstrap.Bootstrap; @@ -26,10 +24,10 @@ public class CustomSniHandler extends SniHandler { private final IterativeHostMatcher ignoredHosts; - public CustomSniHandler(Mapping mapping, Bootstrap clientBootstrapTemplate, Config config) throws IOException { + public CustomSniHandler(Mapping mapping, Bootstrap clientBootstrapTemplate, IterativeHostMatcher ignoredHostMatcher) throws IOException { super(mapping); this.clientBootstrapTemplate = clientBootstrapTemplate; - ignoredHosts = new IterativeHostMatcher<>(List.of(Map.entry(config.ignoredHosts(), new Object()))); + ignoredHosts = ignoredHostMatcher; } @Override