Skip to content

Commit

Permalink
More Oracle (#92)
Browse files Browse the repository at this point in the history
* Fixed a bug with RepoURL.with_origin and relative URLs

* No body for HEAD requests explicitly
  • Loading branch information
dalazx authored Jul 30, 2019
1 parent 3d8c744 commit b8a191e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions platform_registry_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def with_repo(self, repo: str) -> "RepoURL":
return self.__class__(repo=repo, url=url)

def with_origin(self, origin_url: URL) -> "RepoURL":
url = origin_url.join(self.url.relative())
url = self.url
if url.is_absolute():
url = url.relative()
url = origin_url.join(url)
return self.__class__(repo=self.repo, url=url)


Expand Down Expand Up @@ -368,12 +371,17 @@ async def _proxy_request(

timeout = self._create_registry_client_timeout(request)

if request.method == "HEAD":
data = None
else:
data = request.content.iter_any()

async with self._registry_client.request(
method=request.method,
url=url,
headers=request_headers,
skip_auto_headers=("Content-Type",),
data=request.content.iter_any(),
data=data,
timeout=timeout,
) as client_response:

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def test_with_origin(self):
repo="this/image", url=URL("http://a.b/v2/this/image/tags/list?what=ever")
)

def test_with_origin_relative(self):
url = URL("/v2/this/image/tags/list?what=ever")
reg_url = RepoURL.from_url(url).with_origin(URL("http://a.b"))
assert reg_url == RepoURL(
repo="this/image", url=URL("http://a.b/v2/this/image/tags/list?what=ever")
)


class TestURLFactory:
@pytest.fixture
Expand Down

0 comments on commit b8a191e

Please sign in to comment.