Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

cleanup http11 tunneling connection after #1678 - construct string and then convert to bytes

Konstantin Lopuhinf0cf5463c85b
diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.py
index a4d5a28c8..ad3285a32 100644
--- a/scrapy/core/downloader/handlers/http11.py
+++ b/scrapy/core/downloader/handlers/http11.py
@@ -92,11 +92,9 @@ class TunnelingTCP4ClientEndpoint(TCP4ClientEndpoint):
def requestTunnel(self, protocol):
"""Asks the proxy to open a tunnel."""
- tunnelReq = (
- b'CONNECT ' +
- to_bytes(self._tunneledHost, encoding='ascii') + b':' +
- to_bytes(str(self._tunneledPort)) +
- b' HTTP/1.1\r\n')
+ tunnelReq = to_bytes(
+ 'CONNECT %s:%s HTTP/1.1\r\n' % (
+ self._tunneledHost, self._tunneledPort), encoding='ascii')
if self._proxyAuthHeader:
tunnelReq += \
b'Proxy-Authorization: ' + self._proxyAuthHeader + b'\r\n'