From b328b86b68dc0cb92add0ca0e47ad997cd65d405 Mon Sep 17 00:00:00 2001 From: Ted Timmons Date: Thu, 2 Feb 2023 19:37:30 -0800 Subject: [PATCH] Revert "Compute host header correctly" This reverts commit 8e1417c3af7239ec42deb2d786ee082076a3d137. Fixing #34 and #63 caused a regression bug. --- requests_aws4auth/aws4auth.py | 10 +--------- requests_aws4auth/test/test_requests_aws4auth.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/requests_aws4auth/aws4auth.py b/requests_aws4auth/aws4auth.py index 2370378..e0b55ff 100644 --- a/requests_aws4auth/aws4auth.py +++ b/requests_aws4auth/aws4auth.py @@ -615,15 +615,7 @@ def get_canonical_headers(cls, req, include=None): # in the signed headers, but Requests doesn't include it in a # PreparedRequest if 'host' not in headers: - purl = urlparse(str(req.url)) - netloc = purl.netloc - # Python's http client only includes the port if it is non-default, - # see http.client.HTTPConnection.putrequest. The request URL, on the - # other hand, might explicitly include it. - if ((purl.port == 80 and purl.scheme == 'http') - or (purl.port == 443 and purl.scheme == 'https')): - netloc = netloc.rsplit(":", 1)[0] - headers['host'] = netloc + headers['host'] = urlparse(str(req.url)).netloc.split(':')[0] # Aggregate for upper/lowercase header name collisions in header names, # AMZ requires values of colliding headers be concatenated into a # single header with lowercase name. Although this is not possible with diff --git a/requests_aws4auth/test/test_requests_aws4auth.py b/requests_aws4auth/test/test_requests_aws4auth.py index 7be3134..dd25dc2 100644 --- a/requests_aws4auth/test/test_requests_aws4auth.py +++ b/requests_aws4auth/test/test_requests_aws4auth.py @@ -949,7 +949,7 @@ def test_netloc_port(self): request. """ - req = requests.Request('GET', 'https://amazonaws.com:443') + req = requests.Request('GET', 'http://amazonaws.com:8443') preq = req.prepare() self.assertNotIn('host', preq.headers) result = AWS4Auth.get_canonical_headers(preq, include=['host'])