Skip to content

HTTPS requests with proxy broken, because HTTP status line include full URL #2810

Closed
@datakurre

Description

Long story short

When I used aiohttp with proxy to fetch https resource, I always got only the front page of the requested domain, because aiohttp wrongly included domain in the eventual get request.

Expected behaviour

CONNECT example.com:443 HTTP/1.1
Host: example.com
Accept-Encoding: gzip, deflate
User-Agent: Python/3.6 aiohttp/3.0.1
GET /some/path HTTP/1.1
Accept-Encoding: gzip, deflate
Host: example.com
User-Agent: Python/3.6 aiohttp/3.0.1

Actual behaviour

CONNECT example.com:443 HTTP/1.1
Host: example.com
Accept-Encoding: gzip, deflate
User-Agent: Python/3.6 aiohttp/3.0.1
GET https://example.com/some/path HTTP/1.1
Accept-Encoding: gzip, deflate
Host: example.com
User-Agent: Python/3.6 aiohttp/3.0.1

I located the issue to this commit:

3f283c6

And patched it locally with:

diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py
index 33bd25ca..31c0ce93 100644
--- a/aiohttp/client_reqrep.py
+++ b/aiohttp/client_reqrep.py
@@ -472,7 +472,7 @@ class ClientRequest:
         # - most common is origin form URI
         if self.method == hdrs.METH_CONNECT:
             path = '{}:{}'.format(self.url.raw_host, self.url.port)
-        elif self.proxy and not self.ssl:
+        elif self.proxy and not self.ssl and not self.url.scheme == 'https':
             path = str(self.url)
         else:
             path = self.url.raw_path

Not sure what would be the optimal test to separate proxied http requests from proxied https requests.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions