Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
looyolo
scrapy
提交
57d04aa9
S
scrapy
项目概览
looyolo
/
scrapy
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrapy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
57d04aa9
编写于
12月 26, 2017
作者:
D
Daniel Graña
提交者:
GitHub
12月 26, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2767 from redapple/http-proxy-endpoint-key
[MRG+1] Use HTTP pool and proper endpoint key for ProxyAgent
上级
930f6ed8
6b092c66
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
4 deletion
+35
-4
scrapy/core/downloader/handlers/http11.py
scrapy/core/downloader/handlers/http11.py
+35
-4
未找到文件。
scrapy/core/downloader/handlers/http11.py
浏览文件 @
57d04aa9
...
...
@@ -15,6 +15,10 @@ from twisted.internet.error import TimeoutError
from
twisted.web.http
import
_DataLoss
,
PotentialDataLoss
from
twisted.web.client
import
Agent
,
ProxyAgent
,
ResponseDone
,
\
HTTPConnectionPool
,
ResponseFailed
try
:
from
twisted.web.client
import
URI
except
ImportError
:
from
twisted.web.client
import
_URI
as
URI
from
twisted.internet.endpoints
import
TCP4ClientEndpoint
from
scrapy.http
import
Headers
...
...
@@ -228,10 +232,38 @@ class TunnelingAgent(Agent):
headers
,
bodyProducer
,
requestPath
)
class
ScrapyProxyAgent
(
Agent
):
def
__init__
(
self
,
reactor
,
proxyURI
,
connectTimeout
=
None
,
bindAddress
=
None
,
pool
=
None
):
super
(
ScrapyProxyAgent
,
self
).
__init__
(
reactor
,
connectTimeout
=
connectTimeout
,
bindAddress
=
bindAddress
,
pool
=
pool
)
self
.
_proxyURI
=
URI
.
fromBytes
(
proxyURI
)
def
request
(
self
,
method
,
uri
,
headers
=
None
,
bodyProducer
=
None
):
"""
Issue a new request via the configured proxy.
"""
# Cache *all* connections under the same key, since we are only
# connecting to a single destination, the proxy:
if
twisted_version
>=
(
15
,
0
,
0
):
proxyEndpoint
=
self
.
_getEndpoint
(
self
.
_proxyURI
)
else
:
proxyEndpoint
=
self
.
_getEndpoint
(
self
.
_proxyURI
.
scheme
,
self
.
_proxyURI
.
host
,
self
.
_proxyURI
.
port
)
key
=
(
"http-proxy"
,
self
.
_proxyURI
.
host
,
self
.
_proxyURI
.
port
)
return
self
.
_requestWithEndpoint
(
key
,
proxyEndpoint
,
method
,
URI
.
fromBytes
(
uri
),
headers
,
bodyProducer
,
uri
)
class
ScrapyAgent
(
object
):
_Agent
=
Agent
_ProxyAgent
=
ProxyAgent
_ProxyAgent
=
Scrapy
ProxyAgent
_TunnelingAgent
=
TunnelingAgent
def
__init__
(
self
,
contextFactory
=
None
,
connectTimeout
=
10
,
bindAddress
=
None
,
pool
=
None
,
...
...
@@ -260,9 +292,8 @@ class ScrapyAgent(object):
contextFactory
=
self
.
_contextFactory
,
connectTimeout
=
timeout
,
bindAddress
=
bindaddress
,
pool
=
self
.
_pool
)
else
:
endpoint
=
TCP4ClientEndpoint
(
reactor
,
proxyHost
,
proxyPort
,
timeout
=
timeout
,
bindAddress
=
bindaddress
)
return
self
.
_ProxyAgent
(
endpoint
)
return
self
.
_ProxyAgent
(
reactor
,
proxyURI
=
to_bytes
(
proxy
,
encoding
=
'ascii'
),
connectTimeout
=
timeout
,
bindAddress
=
bindaddress
,
pool
=
self
.
_pool
)
return
self
.
_Agent
(
reactor
,
contextFactory
=
self
.
_contextFactory
,
connectTimeout
=
timeout
,
bindAddress
=
bindaddress
,
pool
=
self
.
_pool
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录