Skip to content

Commit f3470aa

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 f3470aa

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changes for crate
55
Unreleased
66
==========
77

8+
- Fixed a regression introduced in 2.1.0 that caused fetching blobs to fail
9+
with a ``DigestNotFoundException`` if it required following a redirect.
10+
811
2026/03/04 2.1.1
912
================
1013

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)