Skip to content

Commit 86e4442

Browse files
committed
Fix HTTP Pool key for HTTPS proxy tunneled connections (CONNECT method)
1 parent 10d03ee commit 86e4442

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

scrapy/core/downloader/handlers/http11.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def processProxyResponse(self, bytes):
127127
self._tunnelReadyDeferred.callback(self._protocol)
128128
else:
129129
self._tunnelReadyDeferred.errback(
130-
TunnelError('Could not open CONNECT tunnel.'))
130+
TunnelError('Could not open CONNECT tunnel with proxy %s:%s' % (
131+
self._host, self._port)))
131132

132133
def connectFailed(self, reason):
133134
"""Propagates the errback to the appropriate deferred."""
@@ -193,6 +194,14 @@ def _getEndpoint(self, scheme, host, port):
193194
self._contextFactory, self._connectTimeout,
194195
self._bindAddress)
195196

197+
def _requestWithEndpoint(self, key, endpoint, method, parsedURI,
198+
headers, bodyProducer, requestPath):
199+
# proxy host and port are required for HTTP pool `key`
200+
# otherwise, same remote host connection request could reuse
201+
# a cached tunneled connection to a different proxy
202+
key = key + self._proxyConf
203+
return super(TunnelingAgent, self)._requestWithEndpoint(key, endpoint, method, parsedURI,
204+
headers, bodyProducer, requestPath)
196205

197206

198207
class ScrapyAgent(object):

0 commit comments

Comments
 (0)