Skip to content

Commit

Permalink
针对百度云400响应调整
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Mar 28, 2018
1 parent adac5c2 commit 0ce34ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import io.netty.util.ReferenceCountUtil;
import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import lee.study.down.boot.AbstractHttpDownBootstrap;
import lee.study.down.constant.HttpDownStatus;
import lee.study.down.dispatch.HttpDownCallback;
Expand All @@ -26,6 +28,7 @@
public class HttpDownInitializer extends ChannelInitializer {

private static final Logger LOGGER = LoggerFactory.getLogger(HttpDownInitializer.class);
private static Executor executor = Executors.newFixedThreadPool(4);

private boolean isSsl;
private AbstractHttpDownBootstrap bootstrap;
Expand Down Expand Up @@ -122,9 +125,20 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
if (HttpUtil
.checkUrl(bootstrap.getHttpDownInfo().getRequest(), "^.*.baidupcs.com.*$")
&& httpResponse.status().code() == 400) {
executor.execute(() -> {
safeClose(ctx.channel());
chunkInfo.setStatus(HttpDownStatus.CONNECTING_NORMAL);
try {
Thread.sleep(2000);
bootstrap.retryChunkDown(chunkInfo);
} catch (Exception e) {
e.printStackTrace();
}
});
return;
} else {
chunkInfo.setErrorCount(chunkInfo.getErrorCount() + 1);
}
chunkInfo.setErrorCount(chunkInfo.getErrorCount() + 1);
throw new RuntimeException("http down response error:" + httpResponse);
}
realContentSize = HttpDownUtil.getDownContentSize(httpResponse.headers());
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ConfigBaseInfo {
private int sniffModel = 2; //嗅探模式 1.全网 2.百度云 3.关闭
private int uiModel = 1; //嗅探模式 1.GUI 2.浏览器
private int connections = 32; //默认分段数
private int timeout = 10; //超时重试时间
private int timeout = 30; //超时重试时间
private boolean secProxyEnable; //二级代理开关
private String lastPath; //最后保存文件的路径
private int retryCount = 5; //失败重试次数
Expand Down

0 comments on commit 0ce34ec

Please sign in to comment.