monkeyWie / proxyee

HTTP proxy server,support HTTPS&websocket.MITM impl,intercept and tamper HTTPS traffic.
MIT License
1.51k stars 566 forks source link

拦截器的beforeRequest()未调用 #157

Closed siwee closed 3 years ago

siwee commented 3 years ago

我打算在beforeRequest()中设置代理策略,根据不同的url使用不同的代理服务器,但是调试发现beforeRequest()并未调用,代码如下:

public class InterceptorJsIntercept2 extends FullRequestIntercept {

    @Override
    public void beforeRequest(Channel clientChannel, HttpContent httpContent, HttpProxyInterceptPipeline pipeline) throws Exception {
        String host = pipeline.getRequestProto().getHost();
        if (host.contains("taobao.com")) {
            pipeline.setProxyConfig(new ProxyConfig(ProxyType.HTTP, "127.0.0.1", 8888));
        } else {
            pipeline.setProxyConfig(new ProxyConfig(ProxyType.HTTP, "127.0.0.1", 7890));
        }
        super.beforeRequest(clientChannel, httpContent, pipeline);
    }

    @Override
    public boolean match(HttpRequest httpRequest, HttpProxyInterceptPipeline pipeline) {
        return true;
    }
}

aomsweet 谢谢。

monkeyWie commented 3 years ago

FullRequestIntercept需要重写这个方法才行:

public void handleRequest(FullHttpRequest httpRequest, HttpProxyInterceptPipeline pipeline)
siwee commented 3 years ago

@monkeyWie 嗯嗯,后面试了这个方法,确实可以。

谢谢。