s3cmd
s3cmd copied to clipboard
Redirect fails when the URL in location header contains a port number
When s3cmd gets a 301 response with a location header that contains a port number, such as:
location: http://1.5.11.69:8002/test-bucket/file-1
It will be redirected to 1.5.11.69, instead of 1.5.11.69:8002. I checked the code and found that the issue is with this line in S3.py:
location_url = urlparse('https://' + location_url).hostname
at line 1440.
It should be:
location_url = urlparse('https://' + location_url).netloc
since hostname doesn't contain the port part.
After this simple change, redirect works.