Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
25c81013
Commit
25c81013
authored
Mar 20, 2017
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new proxy pool api
parent
46297dea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
11 deletions
+7
-11
Site.java
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
+0
-5
HttpClientDownloader.java
...s/codecraft/webmagic/downloader/HttpClientDownloader.java
+3
-3
ProxyPool.java
.../src/main/java/us/codecraft/webmagic/proxy/ProxyPool.java
+4
-3
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
View file @
25c81013
...
...
@@ -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
();
}
}
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java
View file @
25c81013
...
...
@@ -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
.
getHttpProxy
FromPool
(
);
if
(
site
.
getHttpProxyPool
()
!=
null
)
{
proxy
=
site
.
getHttpProxy
Pool
().
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
);
}
}
}
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/proxy/ProxyPool.java
View file @
25c81013
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
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment