Skip to content

Commit

Permalink
only initialize ignored hosts matcher once
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Mar 8, 2024
1 parent be4dff8 commit a23c751
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class ServerHandlersInit extends ChannelInitializer<SocketChannel> {
private final SNIHandlerMapping sniMapping;
private final Config config;

private IterativeHostMatcher<PreForwardRule> preForwardMatcher;
private final IterativeHostMatcher<PreForwardRule> preForwardMatcher;
private final IterativeHostMatcher<Object> ignoredHostMatcher;

public ServerHandlersInit(Bootstrap clientBootstrap, Config config) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
this.clientBootstrapTemplate = clientBootstrap;
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,10 +24,10 @@ public class CustomSniHandler extends SniHandler {

private final IterativeHostMatcher<Object> ignoredHosts;

public CustomSniHandler(Mapping<? super String, ? extends SslContext> mapping, Bootstrap clientBootstrapTemplate, Config config) throws IOException {
public CustomSniHandler(Mapping<? super String, ? extends SslContext> mapping, Bootstrap clientBootstrapTemplate, IterativeHostMatcher<Object> ignoredHostMatcher) throws IOException {
super(mapping);
this.clientBootstrapTemplate = clientBootstrapTemplate;
ignoredHosts = new IterativeHostMatcher<>(List.of(Map.entry(config.ignoredHosts(), new Object())));
ignoredHosts = ignoredHostMatcher;
}

@Override
Expand Down

0 comments on commit a23c751

Please sign in to comment.