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);
}
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);
}
};
}
Aggregations