correctly construct host header value

pull/13/head
Arjen Brouwer 2020-01-20 21:05:50 +01:00
parent e3a2e2d631
commit 374529ec7c
1 changed files with 10 additions and 1 deletions

View File

@ -82,7 +82,16 @@ class HTTPSignatureAuth(requests.auth.AuthBase):
sts.append("(request-target): {} {}".format(request.method.lower(), path_url))
else:
if header.lower() == "host":
value = request.headers.get("host", urlparse(request.url).hostname)
url = urlparse(request.url)
value = request.headers.get("host", url.hostname)
if (
url.scheme == "http"
and url.port not in [None, 80]
or url.scheme == "https"
and url.port not in [443, None]
):
value = "{}:{}".format(value, url.port)
else:
value = request.headers[header]
sts.append("{k}: {v}".format(k=header.lower(), v=value))