Commit b8f9547a by John Peter Yamauchi Committed by GitHub

legacy repository: support redirected url

parent e36fb739
...@@ -387,8 +387,17 @@ class LegacyRepository(PyPiRepository): ...@@ -387,8 +387,17 @@ class LegacyRepository(PyPiRepository):
if response.status_code in (401, 403): if response.status_code in (401, 403):
self._log( self._log(
"Authorization error accessing {url}".format(url=url), level="warn" "Authorization error accessing {url}".format(url=response.url),
level="warn",
) )
return return
return Page(url, response.content, response.headers) if response.url != url:
self._log(
"Response URL {response_url} differs from request URL {url}".format(
response_url=response.url, url=url
),
level="debug",
)
return Page(response.url, response.content, response.headers)
...@@ -3,6 +3,7 @@ import shutil ...@@ -3,6 +3,7 @@ import shutil
from pathlib import Path from pathlib import Path
import pytest import pytest
import requests
from poetry.core.packages import Dependency from poetry.core.packages import Dependency
from poetry.factory import Factory from poetry.factory import Factory
...@@ -322,3 +323,17 @@ def test_get_4xx_and_5xx_raises(http): ...@@ -322,3 +323,17 @@ def test_get_4xx_and_5xx_raises(http):
for endpoint in endpoints: for endpoint in endpoints:
with pytest.raises(RepositoryError): with pytest.raises(RepositoryError):
repo._get(endpoint) repo._get(endpoint)
def test_get_redirected_response_url(http, monkeypatch):
repo = MockHttpRepository({"/foo": 200}, http)
redirect_url = "http://legacy.redirect.bar"
def get_mock(url):
response = requests.Response()
response.status_code = 200
response.url = redirect_url + "/foo"
return response
monkeypatch.setattr(repo.session, "get", get_mock)
assert repo._get("/foo")._url == "http://legacy.redirect.bar/foo/"
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