-
-
Notifications
You must be signed in to change notification settings - Fork 586
Open
Description
使用这些代码,在match
方法的return
上打断点,发现使用HTTP
请求会被拦截,但是使用HTTPS
请求则不会被拦截。
fun main() {
val config = HttpProxyServerConfig()
config.isHandleSsl = true
HttpProxyServer().apply {
serverConfig(config)
proxyInterceptInitializer(object : HttpProxyInterceptInitializer() {
override fun init(pipeline: HttpProxyInterceptPipeline) {
pipeline.addLast(CertDownIntercept())
pipeline.addLast(object : FullResponseIntercept() {
override fun match(
httpRequest: HttpRequest,
httpResponse: HttpResponse,
pipeline: HttpProxyInterceptPipeline
): Boolean {
return true
}
override fun handleResponse(
httpRequest: HttpRequest?,
httpResponse: FullHttpResponse?,
pipeline: HttpProxyInterceptPipeline?
) {
super.handleResponse(httpRequest, httpResponse, pipeline)
}
})
}
})
start(9999)
}
}
排查源码发现,收到HTTPS
请求时,setInterceptPipeline(buildPipeline())
没有被调用。
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
if (msg instanceof HttpRequest) {
// 省略
if (getStatus() == 0) {
// 省略
setStatus(1);
if (HttpMethod.CONNECT.name().equalsIgnoreCase(request.method().name())) {// 建立代理握手
setStatus(2);
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpProxyServer.SUCCESS);
ctx.writeAndFlush(response);
ctx.channel().pipeline().remove("httpCodec");
// fix issue #42
ReferenceCountUtil.release(msg);
return;
}
}
setInterceptPipeline(buildPipeline());
// 省略
}
}
到这里直接跳过了后面的代码执行,不会执行setInterceptPipeline(buildPipeline());
部分。
请问是我的调用出现问题了吗?还是其他版本没有出现这个问题?
Using these codes, break the point on the return
of the match
method and find that requests using HTTP
will be intercepted, but requests using HTTPS
will not be intercepted.
fun main() {
val config = HttpProxyServerConfig()
config.isHandleSsl = true
HttpProxyServer().apply {
serverConfig(config)
proxyInterceptInitializer(object : HttpProxyInterceptInitializer() {
override fun init(pipeline: HttpProxyInterceptPipeline) {
pipeline.addLast(CertDownIntercept())
pipeline.addLast(object : FullResponseIntercept() {
override fun match(
httpRequest: HttpRequest,
httpResponse: HttpResponse,
pipeline: HttpProxyInterceptPipeline
): Boolean {
return true
}
override fun handleResponse(
httpRequest: HttpRequest?,
httpResponse: FullHttpResponse?,
pipeline: HttpProxyInterceptPipeline?
) {
super.handleResponse(httpRequest, httpResponse, pipeline)
}
})
}
})
start(9999)
}
}
After checking the source code, we found that setInterceptPipeline(buildPipeline())
was not called when receiving an HTTPS
request.
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
if (msg instanceof HttpRequest) {
// Omit
if (getStatus() == 0) {
// Omit
setStatus(1);
if (HttpMethod.CONNECT.name().equalsIgnoreCase(request.method().name())) {// Establish proxy handshake
setStatus(2);
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpProxyServer.SUCCESS);
ctx.writeAndFlush(response);
ctx.channel().pipeline().remove("httpCodec");
// fix issue #42
ReferenceCountUtil.release(msg);
return;
}
}
setInterceptPipeline(buildPipeline());
// Omit
}
}
The subsequent code execution is skipped here, and the setInterceptPipeline(buildPipeline());
part will not be executed.
Is there something wrong with my call? Or does this problem not occur in other versions?
Metadata
Metadata
Assignees
Labels
No labels