Search in sources :

Example 1 with HttpProxyIntercept

use of lee.study.proxyee.intercept.HttpProxyIntercept in project proxyee-down by monkeyWie.

the class HttpDownProxyServer method start.

public void start(int port) {
    LOGGER.debug("HttpDownProxyServer listen " + port + "\tproxyConfig:" + proxyConfig);
    // 监听http下载请求
    proxyServer.proxyConfig(proxyConfig);
    proxyServer.proxyInterceptInitializer(new HttpProxyInterceptInitializer() {

        @Override
        public void init(HttpProxyInterceptPipeline pipeline) {
            pipeline.addLast(new BdyIntercept());
            pipeline.addLast(new HttpDownSniffIntercept());
            HttpProxyIntercept downIntercept = interceptFactory.create();
            if (downIntercept != null) {
                pipeline.addLast(downIntercept);
            }
        }
    }).httpProxyExceptionHandle(new HttpProxyExceptionHandle() {

        @Override
        public void beforeCatch(Channel clientChannel, Throwable cause) throws Exception {
            LOGGER.warn("beforeCatch:", cause);
        }

        @Override
        public void afterCatch(Channel clientChannel, Channel proxyChannel, Throwable cause) throws Exception {
            LOGGER.warn("afterCatch:", cause);
        }
    }).start(port);
}
Also used : BdyIntercept(lee.study.down.intercept.BdyIntercept) Channel(io.netty.channel.Channel) HttpProxyIntercept(lee.study.proxyee.intercept.HttpProxyIntercept) HttpProxyExceptionHandle(lee.study.proxyee.exception.HttpProxyExceptionHandle) HttpDownSniffIntercept(lee.study.down.intercept.HttpDownSniffIntercept) HttpProxyInterceptPipeline(lee.study.proxyee.intercept.HttpProxyInterceptPipeline) HttpProxyInterceptInitializer(lee.study.proxyee.intercept.HttpProxyInterceptInitializer)

Example 2 with HttpProxyIntercept

use of lee.study.proxyee.intercept.HttpProxyIntercept in project proxyee-down by monkeyWie.

the class HttpDownHandleInterceptFactory method create.

@Override
public HttpProxyIntercept create() {
    return new HttpProxyIntercept() {

        @Override
        public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception {
            HttpRequest httpRequest = pipeline.getHttpRequest();
            ProxyConfig proxyConfig = ContentManager.CONFIG.get().getSecProxyConfig();
            TaskInfo taskInfo = HttpDownUtil.getTaskInfo(httpRequest, httpResponse.headers(), proxyConfig, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup);
            HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, httpRequest, proxyConfig);
            ContentManager.DOWN.putBoot(httpDownInfo);
            httpResponse.setStatus(HttpResponseStatus.OK);
            httpResponse.headers().clear();
            httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
            byte[] content;
            if (HttpUtil.checkHead(httpRequest, HttpHeaderNames.HOST, "^.*\\.baidupcs\\.com.*$")) {
                content = "<script>window.close();</script>".getBytes();
            } else {
                content = "<script>window.history.go(-1);</script>".getBytes();
            }
            httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length);
            clientChannel.writeAndFlush(httpResponse);
            HttpContent httpContent = new DefaultLastHttpContent();
            httpContent.content().writeBytes(content);
            clientChannel.writeAndFlush(httpContent);
            clientChannel.close();
            httpDownDispatch.dispatch(httpDownInfo);
        }
    };
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) TaskInfo(lee.study.down.model.TaskInfo) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Channel(io.netty.channel.Channel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpProxyIntercept(lee.study.proxyee.intercept.HttpProxyIntercept) ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) HttpDownInfo(lee.study.down.model.HttpDownInfo) HttpProxyInterceptPipeline(lee.study.proxyee.intercept.HttpProxyInterceptPipeline) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent)

Aggregations

Channel (io.netty.channel.Channel)2 HttpProxyIntercept (lee.study.proxyee.intercept.HttpProxyIntercept)2 HttpProxyInterceptPipeline (lee.study.proxyee.intercept.HttpProxyInterceptPipeline)2 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 BdyIntercept (lee.study.down.intercept.BdyIntercept)1 HttpDownSniffIntercept (lee.study.down.intercept.HttpDownSniffIntercept)1 HttpDownInfo (lee.study.down.model.HttpDownInfo)1 TaskInfo (lee.study.down.model.TaskInfo)1 HttpProxyExceptionHandle (lee.study.proxyee.exception.HttpProxyExceptionHandle)1 HttpProxyInterceptInitializer (lee.study.proxyee.intercept.HttpProxyInterceptInitializer)1 ProxyConfig (lee.study.proxyee.proxy.ProxyConfig)1