Skip to content

Commit a3d0e57

Browse files
authored
feat: support user defined ChannelFactory and forseResolveDNS (#310)
1 parent cddd02a commit a3d0e57

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/main/java/com/github/monkeywie/proxyee/handler/HttpProxyServerHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ private void handleProxyData(Channel channel, Object msg, boolean isHttp) throws
336336
: new TunnelProxyInitializer(channel, proxyHandler);
337337
Bootstrap bootstrap = new Bootstrap();
338338
bootstrap.group(getServerConfig().getProxyLoopGroup()) // 注册线程池
339-
.channel(NioSocketChannel.class) // 使用NioSocketChannel来作为连接用的channel类
339+
.channelFactory(getServerConfig().getChannelFactory())
340340
.handler(channelInitializer);
341-
if (proxyHandler != null) {
341+
if (proxyHandler != null && !getServerConfig().getForceResolveDNS()) {
342342
// 代理服务器解析DNS和连接
343343
bootstrap.resolver(NoopAddressResolverGroup.INSTANCE);
344344
} else {

src/main/java/com/github/monkeywie/proxyee/server/HttpProxyServerConfig.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import com.github.monkeywie.proxyee.server.accept.HttpProxyMitmMatcher;
55
import com.github.monkeywie.proxyee.server.auth.HttpProxyAuthenticationProvider;
66
import com.github.monkeywie.proxyee.config.IdleStateCheck;
7+
8+
import io.netty.channel.ChannelFactory;
79
import io.netty.channel.EventLoopGroup;
10+
import io.netty.channel.socket.SocketChannel;
11+
import io.netty.channel.socket.nio.NioSocketChannel;
812
import io.netty.handler.codec.http.HttpObjectDecoder;
913
import io.netty.handler.ssl.SslContext;
1014
import io.netty.resolver.AddressResolverGroup;
@@ -37,6 +41,8 @@ public class HttpProxyServerConfig {
3741
private int maxHeaderSize = HttpObjectDecoder.DEFAULT_MAX_HEADER_SIZE;
3842
private int maxChunkSize = HttpObjectDecoder.DEFAULT_MAX_CHUNK_SIZE;
3943
private IdleStateCheck idleStateCheck;
44+
private ChannelFactory<SocketChannel> channelFactory;
45+
private boolean forceResolveDNS = false;
4046

4147
public HttpProxyServerConfig() {
4248
this(DefaultAddressResolverGroup.INSTANCE);
@@ -67,6 +73,30 @@ private HttpProxyServerConfig(Builder builder) {
6773
this.idleStateCheck = builder.idleStateCheck;
6874
}
6975

76+
public void setForceResolveDNS(boolean forceResolveDNS) {
77+
this.forceResolveDNS = forceResolveDNS;
78+
}
79+
80+
public boolean getForceResolveDNS() {
81+
return forceResolveDNS;
82+
}
83+
84+
public ChannelFactory<SocketChannel> getChannelFactory() {
85+
if (channelFactory == null) {
86+
return (new ChannelFactory<SocketChannel>() {
87+
@Override
88+
public SocketChannel newChannel() {
89+
return new NioSocketChannel(); // 使用NioSocketChannel来作为连接用的channel类
90+
}
91+
});
92+
}
93+
return channelFactory;
94+
}
95+
96+
public void setChannelFactory(ChannelFactory<SocketChannel> channelFactory) {
97+
this.channelFactory = channelFactory;
98+
}
99+
70100
public SslContext getClientSslCtx() {
71101
return clientSslCtx;
72102
}

0 commit comments

Comments
 (0)