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
3ee00015
Commit
3ee00015
authored
Jun 17, 2017
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change header from Authorization to Proxy-Authorization for Proxy Authorization #596
parent
4111b072
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
HttpUriRequestConverter.java
...odecraft/webmagic/downloader/HttpUriRequestConverter.java
+2
-1
HttpClientDownloaderTest.java
...decraft/webmagic/downloader/HttpClientDownloaderTest.java
+14
-9
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpUriRequestConverter.java
View file @
3ee00015
...
...
@@ -2,6 +2,7 @@ package us.codecraft.webmagic.downloader;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthState
;
import
org.apache.http.auth.ChallengeState
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.config.CookieSpecs
;
...
...
@@ -41,7 +42,7 @@ public class HttpUriRequestConverter {
HttpClientContext
httpContext
=
new
HttpClientContext
();
if
(
proxy
!=
null
&&
proxy
.
getUsername
()
!=
null
)
{
AuthState
authState
=
new
AuthState
();
authState
.
update
(
new
BasicScheme
(),
new
UsernamePasswordCredentials
(
proxy
.
getUsername
(),
proxy
.
getPassword
()));
authState
.
update
(
new
BasicScheme
(
ChallengeState
.
PROXY
),
new
UsernamePasswordCredentials
(
proxy
.
getUsername
(),
proxy
.
getPassword
()));
httpContext
.
setAttribute
(
HttpClientContext
.
PROXY_AUTH_STATE
,
authState
);
}
if
(
request
.
getCookies
()
!=
null
&&
!
request
.
getCookies
().
isEmpty
())
{
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/downloader/HttpClientDownloaderTest.java
View file @
3ee00015
...
...
@@ -10,7 +10,6 @@ import org.apache.http.client.methods.HttpUriRequest;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
us.codecraft.webmagic.Page
;
import
us.codecraft.webmagic.Request
;
...
...
@@ -255,15 +254,21 @@ public class HttpClientDownloaderTest {
});
}
@Ignore
(
"need proxy server"
)
@Test
public
void
test_download_by_SimpleProxyProvider
(){
public
void
test_download_auth_by_SimpleProxyProvider
()
throws
Exception
{
HttpServer
server
=
httpServer
(
13423
);
server
.
get
(
eq
(
header
(
"Proxy-Authorization"
),
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
)).
response
(
"ok"
);
Runner
.
running
(
server
,
new
Runnable
()
{
@Override
public
void
run
()
throws
Exception
{
HttpClientDownloader
httpClientDownloader
=
new
HttpClientDownloader
();
httpClientDownloader
.
setProxyProvider
(
SimpleProxyProvider
.
from
(
new
Proxy
(
"127.0.0.1"
,
1087
)));
httpClientDownloader
.
setProxyProvider
(
SimpleProxyProvider
.
from
(
new
Proxy
(
"127.0.0.1"
,
13423
,
"username"
,
"password"
)));
Request
request
=
new
Request
();
request
.
setUrl
(
"https
://www.baidu.com"
);
request
.
setUrl
(
"http
://www.baidu.com"
);
Page
page
=
httpClientDownloader
.
download
(
request
,
Site
.
me
().
toTask
());
assertThat
(
page
.
isDownloadSuccess
());
assertThat
(
page
.
getRawText
()).
isEqualTo
(
"ok"
);
}
});
}
}
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