Skip to content

Commit dca7b4f

Browse files
committed
Fix blob redirect handling regression
#771 broke the redirect handling because the redirect location returned by CrateDB includes the full path to the blob. E.g. `http://localhost:4202/_blobs/b1/2c2bbc39c1c8b8c217c04cf5fc0dcb23c6d93b39` With the change in the above PR, `_server_url` retained the path and the follow up request was made to `http://localhost:4202/_blobs/b1/2c2b.../_blobs/b1/2c2b...`, leading to a 404 and a BlobDigestNotFound exception. crate-qa tests failed because of that.
1 parent a116102 commit dca7b4f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/crate/client/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,8 @@ def _request(self, method, path, server=None, **kwargs):
637637
)
638638
redirect_location = response.get_redirect_location()
639639
if redirect_location and 300 <= response.status <= 308:
640-
redirect_server = _server_url(redirect_location)
640+
redirect_url = urlparse(redirect_location)
641+
redirect_server = f"{redirect_url.scheme}://{redirect_url.netloc}"
641642
self._add_server(redirect_server)
642643
return self._request(
643644
method, path, server=redirect_server, **kwargs

tests/client/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_redirect_handling():
170170
gets added to the server pool.
171171
"""
172172
with patch(
173-
REQUEST_PATH, return_value=fake_redirect("http://localhost:4201")
173+
REQUEST_PATH, return_value=fake_redirect("http://localhost:4201/_blobs/blobs/fake_digest")
174174
):
175175
client = Client(servers="localhost:4200")
176176

0 commit comments

Comments
 (0)