Commit a5c38466 by Beryl S Committed by GitHub

uploader: fix HTTP status code handling for redirects (#7160)

parent df9d3c91
......@@ -266,7 +266,7 @@ class Uploader:
f" - Uploading <c1>{file.name}</c1> <fg=green>%percent%%</>"
)
bar.finish()
elif resp.status_code == 301:
elif 300 <= resp.status_code < 400:
if self._io.output.is_decorated():
self._io.overwrite(
f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
......
......@@ -65,6 +65,32 @@ def test_uploader_properly_handles_nonstandard_errors(
assert str(e.value) == f"HTTP Error 400: Bad Request | {content}"
@pytest.mark.parametrize(
"status, body",
[
(308, "Permanent Redirect"),
(307, "Temporary Redirect"),
(304, "Not Modified"),
(303, "See Other"),
(302, "Found"),
(301, "Moved Permanently"),
(300, "Multiple Choices"),
],
)
def test_uploader_properly_handles_redirects(
http: type[httpretty.httpretty], uploader: Uploader, status: int, body: str
):
http.register_uri(http.POST, "https://foo.com", status=status, body=body)
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
assert (
str(e.value)
== "Redirects are not supported. Is the URL missing a trailing slash?"
)
def test_uploader_properly_handles_301_redirects(
http: type[httpretty.httpretty], uploader: Uploader
):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment