Skip to content

Commit 6b179c3

Browse files
author
zhangheng09
committed
这个改动的原因基于两点:1)代理归还给代理池的时机应该是执行完http请求后就要尽早归还 2)http代理应该是HttpClientDownloader该考虑的事,不应该有Spider来处理,Spider并不知道它的downloader是个HttpClientDownloader
1 parent 5f106c9 commit 6b179c3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ public void run() {
325325
onError(requestFinal);
326326
logger.error("process request " + requestFinal + " error", e);
327327
} finally {
328-
if (site.getHttpProxyPool()!=null && site.getHttpProxyPool().isEnable()) {
329-
site.returnHttpProxyToPool((HttpHost) requestFinal.getExtra(Request.PROXY), (Integer) requestFinal
330-
.getExtra(Request.STATUS_CODE));
331-
}
332328
pageCount.incrementAndGet();
333329
signalNewUrl();
334330
}

webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public Page download(Request request, Task task) {
109109
return null;
110110
} finally {
111111
request.putExtra(Request.STATUS_CODE, statusCode);
112+
if (site.getHttpProxyPool()!=null && site.getHttpProxyPool().isEnable()) {
113+
site.returnHttpProxyToPool((HttpHost) request.getExtra(Request.PROXY), (Integer) request
114+
.getExtra(Request.STATUS_CODE));
115+
}
112116
try {
113117
if (httpResponse != null) {
114118
//ensure the connection is released back to pool

0 commit comments

Comments
 (0)