Fix wheel metadata reads after redirects - #21347
Conversation
When a wheel URL redirected, the HEAD request followed the redirect but the range requests still used the original URL. Their HTTP client did not follow redirects, so metadata reads failed and uv downloaded whole wheels. Use the final URL from the HEAD response for range requests. Drop the original Authorization header when that URL is in a different auth realm. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7cad5dd5-3d0d-4a32-8c4b-852d920b7978
|
👋 thanks for the pull, I'll take a look. In what context did you encounter this? |
the day job has moved us to using an Azure Artifacts feed, at which point resolution started downloading whole wheels |
|
This sounded familiar so I pulled some history with Codex, I think there's a bunch of nuance we'll need to consider here:
|
uv test inventory changesThis PR changes the tests when compared with the
|
|
What fun... I had found #18998 and decided it wasn't the same: our HEAD does advertise "Accepts-Ranges: bytes", whereas the other seems to be saying that: even if a HEAD does not advertise support, that might not mean much. But I didn't spot the others, and it seems this is going to be more complicated than I probably want for a drive-by fix. Shall I raise an issue report instead? |
|
If you want to open an issue with details about what happened and some logs that'd be great. I will probably add some more test coverage and weigh a couple different approaches here. I haven't really decided if this change is correct or if something else is more appropriate, I have to refresh my memory on all that context. |
|
AFAIK the testcase here is an accurate representation of the observed real world behaviour (and fails without the fix) so I will just reference that unless you want something specific. |
|
Hi @zanieb, we're a few folks at Microsoft discussing this right now. We can test against a new PyPI proxy feed which is open to the public. It doesn't support PEP 658, but should support range requests. We can create an issue with some more context. |
|
Thanks a public registry is super helpful here. What level of urgency is this for ya'll? |
|
Thanks for asking. It would be great to get in a fix in the next week or so, but no-one is fully blocked here. |
|
I had my own Opus instance have a go at this, and it came up with a very similar solution, branch here. Sol had a go too, but I think it went a bit overboard trying to make things secure. Very cool to see the automations bot at work here! Thanks for taking the time. |
Wheel metadata extraction takes a different path for redirects depending on whether range requests stay within an origin, cross origins, or receive method-specific targets. Capture the current behavior for all three cases, including source credential propagation, cross-origin credential stripping, destination credentials, and the existing streaming fallback. This provides an explicit behavioral baseline for #21347 and its follow-up implementation. These are unit tests overlapping with #21350 --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
When a wheel URL redirected, the HEAD request followed the redirect but the range requests still used the original URL. Their HTTP client did not follow redirects, so metadata reads failed and uv downloaded whole wheels.
Use the final URL from the HEAD response for range requests. Drop the original Authorization header when that URL is in a different auth realm.
A healthy assist from the AI on this: but I am a human in the loop and it looks good to me.
Tested live against a feed that does not support PEP658 but does support range requests; which is what prompted the investigation.