Skip to content

Commit 3735eb8

Browse files
committed
Merge pull request scrapy#1912 from redapple/https-proxy-pool-key
[MRG+1] Fix HTTP Pool key for HTTPS proxy tunneled connections (CONNECT method)
2 parents a8b4947 + 86e4442 commit 3735eb8

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
@@ -135,7 +135,8 @@ def processProxyResponse(self, bytes):
135135
self._tunnelReadyDeferred.callback(self._protocol)
136136
else:
137137
self._tunnelReadyDeferred.errback(
138-
TunnelError('Could not open CONNECT tunnel.'))
138+
TunnelError('Could not open CONNECT tunnel with proxy %s:%s' % (
139+
self._host, self._port)))
139140

140141
def connectFailed(self, reason):
141142
"""Propagates the errback to the appropriate deferred."""
@@ -201,6 +202,14 @@ def _getEndpoint(self, scheme, host, port):
201202
self._contextFactory, self._connectTimeout,
202203
self._bindAddress)
203204

205+
def _requestWithEndpoint(self, key, endpoint, method, parsedURI,
206+
headers, bodyProducer, requestPath):
207+
# proxy host and port are required for HTTP pool `key`
208+
# otherwise, same remote host connection request could reuse
209+
# a cached tunneled connection to a different proxy
210+
key = key + self._proxyConf
211+
return super(TunnelingAgent, self)._requestWithEndpoint(key, endpoint, method, parsedURI,
212+
headers, bodyProducer, requestPath)
204213

205214

206215
class ScrapyAgent(object):

0 commit comments

Comments
 (0)