Skip to content

Handle redirects in the HTTP middleware chain - #909

Draft
zaniebot wants to merge 6 commits into
mainfrom
zb/range-reader-redirects
Draft

zaniebot wants to merge 6 commits into
mainfrom
zb/range-reader-redirects

Conversation

@zaniebot

@zaniebot zaniebot commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

uv normally reads wheel metadata by requesting only part of the file. For Azure Artifacts, redirects were causing uv to fall back to streaming the wheel, even though the server supported requests for individual byte ranges (astral-sh#21347).

The current design came from astral-sh#14126, which fixed credentials being missed after a redirect. reqwest followed redirects without giving uv a chance to look up credentials for the destination, including those in .netrc. uv added its own HTTP client and request builder to ensure those lookups ran.

async_http_range_reader, which uv uses to read parts of the wheel, accepts a standard HTTP client. Previously, uv passed it the client stored inside its own, discarding uv's redirect handling while reqwest's own redirects remained disabled. The initial HEAD request followed redirects, but the subsequent requests for part of the wheel did not.

Here, we attach redirect handling directly to the client shared with that library and remove the extra client and request builder. Each destination still gets its own credential lookup, without forwarding source credentials to other hosts. Each GET uses the original wheel URL because signed redirect targets for HEAD and GET can differ.

Previously, uv fell back to streaming because it did not follow the redirect. If the destination rejects a ranged GET with 403 while allowing a full download, uv will now report the rejection. Retrying the full download in that situation is proposed separately in #917.

@astral-automations-bot astral-automations-bot Bot added the bug Something isn't working label Aug 28, 2026
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from f622575 to ec24130 Compare August 28, 2026 19:37
@zaniebot
zaniebot changed the base branch from main to zb/range-reader-redirect-tests August 28, 2026 19:37
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from 00d7594 to 7ee3d42 Compare August 28, 2026 19:42
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from ec24130 to aec3df9 Compare August 28, 2026 19:43
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from 7ee3d42 to 993537a Compare August 28, 2026 19:47
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from aec3df9 to 4cf5608 Compare August 28, 2026 19:48
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from 993537a to ae18601 Compare August 28, 2026 19:52
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from 4cf5608 to adf7d89 Compare August 28, 2026 19:52
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from ae18601 to a43f680 Compare August 28, 2026 19:55
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from adf7d89 to a37bcc3 Compare August 28, 2026 19:55
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from a43f680 to 043e682 Compare August 28, 2026 20:02
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch 2 times, most recently from d5a99c8 to 5b481d0 Compare August 28, 2026 22:11
@zaniebot
zaniebot force-pushed the zb/range-reader-redirect-tests branch from 043e682 to 197a5b6 Compare August 28, 2026 22:11
@zaniebot
zaniebot changed the base branch from zb/range-reader-redirect-tests to zb/range-reader-request-fallback August 28, 2026 22:12
@zaniebot
zaniebot force-pushed the zb/range-reader-request-fallback branch from c3c093b to 503148f Compare August 28, 2026 22:15
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch 2 times, most recently from 339c300 to 1ed22ad Compare August 29, 2026 14:36
@zaniebot
zaniebot force-pushed the zb/range-reader-request-fallback branch from 503148f to 0185839 Compare August 29, 2026 14:36
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from 1ed22ad to 46b2442 Compare August 29, 2026 14:39
@zaniebot
zaniebot force-pushed the zb/range-reader-request-fallback branch from 0185839 to f04fc45 Compare August 29, 2026 14:39
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/range-reader-request-fallback branch from f04fc45 to 5167ea5 Compare August 31, 2026 14:24
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch 3 times, most recently from 67a24c7 to 9343898 Compare August 31, 2026 18:54
@zaniebot zaniebot changed the title Preserve method-specific redirects for range requests Handle redirects in the HTTP middleware chain Aug 31, 2026
@zaniebot
zaniebot changed the base branch from zb/range-reader-request-fallback to main August 31, 2026 18:54
@zaniebot
zaniebot force-pushed the zb/range-reader-redirects branch from 9343898 to 72b22ae Compare August 31, 2026 18:55
Comment thread crates/uv-client/src/base_client.rs Outdated
let mut client = reqwest_middleware::ClientBuilder::new(client);

// Run redirects before the other middleware so each hop can retry and authenticate.
if matches!(self.redirect_policy, RedirectPolicy::RetriggerMiddleware) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good for this to be exhaustive

Comment thread crates/uv-client/src/base_client.rs Outdated
Comment on lines +842 to +843
/// Unlike the built-in reqwest redirect policies, this sends the redirect request through the
/// entire middleware pipeline again.
/// remaining middleware pipeline again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change a problem?

@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/range-reader-redirects branch 3 times, most recently from 63c1ee4 to 3154a48 Compare September 8, 2026 16:14
@zaniebot zaniebot added priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. size:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. labels Sep 9, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/range-reader-redirects branch from 3154a48 to 304dae4 Compare September 11, 2026 20:02
@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 15.95%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 3 improved benchmarks
✅ 66 untouched benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ ⚠️ Simulation discover_workspace_from_all_members_with_excludes 165.6 ms 139.7 ms +18.57%
⚡ ⚠️ Simulation resolve_warm_jupyter_universal 308.6 ms 268.2 ms +15.1%
⚡ ⚠️ Simulation resolve_warm_jupyter 71.7 ms 62.8 ms +14.22%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/range-reader-redirects (28d1cb0) with main (64e2ac8)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch was successfully deployed

1 active deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority:2 Important: bounded correctness, release reliability, committed work, or proven performance gains. risk:3 Credible risk of meaningful incorrect behavior or regression; bounded or recoverable. size:4 Complex: architectural or security-sensitive work requiring broad or cross-repository context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants