提供出现某种异常刷新代理,异常可配置

pull/976/head
yao 4 years ago
parent ba69eba669
commit 4a6441e7c5

@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
/**
@ -43,6 +44,14 @@ public class HttpClientDownloader extends AbstractDownloader {
private boolean responseHeader = true;
private volatile boolean refreshProxyOnError = false;
private Predicate<Throwable> throwablePredicate = t->false;
public void setThrowablePredicate(Predicate<Throwable> predicate){
this.throwablePredicate = predicate;
}
public void setHttpUriRequestConverter(HttpUriRequestConverter httpUriRequestConverter) {
this.httpUriRequestConverter = httpUriRequestConverter;
}
@ -88,6 +97,9 @@ public class HttpClientDownloader extends AbstractDownloader {
} catch (IOException e) {
logger.warn("download page {} error", request.getUrl(), e);
onError(request,e,proxyProvider);
if(proxyProvider != null && refreshProxyOnError && throwablePredicate.test(e)){
proxyProvider.refreshProxy(task);
}
return page;
} finally {
if (httpResponse != null) {

Loading…
Cancel
Save