Commit 25c81013 authored by yihua.huang's avatar yihua.huang

new proxy pool api

parent 46297dea
......@@ -2,7 +2,6 @@ package us.codecraft.webmagic;
import org.apache.http.HttpHost;
import org.apache.http.auth.UsernamePasswordCredentials;
import us.codecraft.webmagic.proxy.Proxy;
import us.codecraft.webmagic.proxy.ProxyPool;
import us.codecraft.webmagic.proxy.TimerReuseProxyPool;
import us.codecraft.webmagic.utils.UrlUtils;
......@@ -509,8 +508,4 @@ public class Site {
return httpProxyPool;
}
public Proxy getHttpProxyFromPool() {
return httpProxyPool.getProxy();
}
}
......@@ -79,8 +79,8 @@ public class HttpClientDownloader extends AbstractDownloader {
Site site = task.getSite();
Proxy proxy = null;
HttpContext httpContext = new BasicHttpContext();
if (site.getHttpProxyPool() != null && site.getHttpProxyPool().isEnable()) {
proxy = site.getHttpProxyFromPool();
if (site.getHttpProxyPool() != null) {
proxy = site.getHttpProxyPool().getProxy(task);
request.putExtra(Request.PROXY, proxy);
AuthState authState = new AuthState();
authState.update(new BasicScheme(), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
......@@ -112,7 +112,7 @@ public class HttpClientDownloader extends AbstractDownloader {
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
if (proxy != null) {
site.getHttpProxyPool().returnProxy(proxy, statusCode);
site.getHttpProxyPool().returnProxy(proxy, statusCode, task);
}
}
}
......
package us.codecraft.webmagic.proxy;
import us.codecraft.webmagic.Task;
/**
* Created by edwardsbean on 15-2-28.
*/
public interface ProxyPool {
void returnProxy(Proxy proxy, int statusCode);
void returnProxy(Proxy proxy, int statusCode, Task task);
Proxy getProxy();
Proxy getProxy(Task task);
boolean isEnable();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment