fix(media): raise ToolError on redirect response missing Location header - #619
Closed
Preciousuche wants to merge 1 commit into
Closed
Conversation
1 task
Preciousuche
force-pushed
the
fix/tools-media-image-redirect-location
branch
from
August 31, 2026 09:08
e8e3135 to
36b8a3d
Compare
Preciousuche
force-pushed
the
fix/tools-media-image-redirect-location
branch
from
September 1, 2026 07:18
36b8a3d to
6b0dfcb
Compare
Contributor
|
Closing as superseded. Reviewed alongside the other three PRs on issue #616; #773 was picked. Your fix is correct and your tests are good — this was a close call. #773 edged it on test coverage (all five 3xx codes parametrized, a mid-chain redirect asserting the failing hop is named rather than the URL the caller passed, and both sides of the Thanks for the contribution — nothing wrong with this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
closes #616
``### Summary
Fixes
_fetch_image_urlcrashing with `httpx.StreamClosed` when a redirect response omits the `Location` header, and adds test coverage for redirect handling.Problem
When receiving a redirect status code (301, 302, 303, 307, 308) missing a
Locationheader,_fetch_image_urlclosed the response (await resp.aclose()) andbreaked out of the redirect loop. Downstream,resp.raise_for_status()does not raise on 3xx, leading intoasync for chunk in resp.aiter_bytes()on the closed stream. This failed with an internalStreamClosederror rather than a clear explanation.Solution
locationis missing on a redirect response, immediately raise an explicitToolErrornaming the status code, the current URL, and the missing header.tests/test_tools/test_media_image_download_cap.py:Locationheader raises clearToolError.Locationheader is followed and the image downloaded._MAX_REDIRECTSraisesToolError("Too many redirects (>5)").Fixes #616