Skip to content

Commit

Permalink
Revert "Compute host header correctly"
Browse files Browse the repository at this point in the history
This reverts commit 8e1417c.

Fixing #34 and #63 caused a regression bug.
  • Loading branch information
tedder committed Feb 3, 2023
1 parent d5b6f2c commit b328b86
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 1 addition & 9 deletions requests_aws4auth/aws4auth.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requests_aws4auth/test/test_requests_aws4auth.py
Expand Up @@ -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'])
Expand Down

0 comments on commit b328b86

Please sign in to comment.