s3cmd icon indicating copy to clipboard operation
s3cmd copied to clipboard

Redirect fails when the URL in location header contains a port number

Open yima77 opened this issue 2 years ago • 0 comments

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.

yima77 avatar May 11 '23 20:05 yima77