Skip to content

Commit 3987086

Browse files
authored
Merge pull request #3169 from fabiosantoscode/feature/2963-dvc-pull-of-s3-remote-with-https-url
pull: treat HTTP redirects without Location header as error
2 parents 74c5af1 + df22dd4 commit 3987086

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

dvc/remote/http.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,22 @@ def _request(self, method, url, **kwargs):
101101
kwargs.setdefault("timeout", self.REQUEST_TIMEOUT)
102102

103103
try:
104-
return self._session.request(method, url, **kwargs)
104+
res = self._session.request(method, url, **kwargs)
105+
106+
redirect_no_location = (
107+
kwargs["allow_redirects"]
108+
and res.status_code in (301, 302)
109+
and "location" not in res.headers
110+
)
111+
112+
if redirect_no_location:
113+
# AWS s3 doesn't like to add a location header to its redirects
114+
# from https://s3.amazonaws.com/<bucket name>/* type URLs.
115+
# This should be treated as an error
116+
raise requests.exceptions.RequestException
117+
118+
return res
119+
105120
except requests.exceptions.RequestException:
106121
raise DvcException("could not perform a {} request".format(method))
107122

0 commit comments

Comments
 (0)