Repository navigation
fix(download): follow Telegram redirect chains - #259
dajiaohuang wants to merge 2 commits into
Conversation
Arpit-Khandelwal
left a comment
There was a problem hiding this comment.
Thanks for looking into #205! I tried to reproduce it, and I don't think a long redirect chain is the cause. A Telegram Web link (https://web.telegram.org/k/d/...) only works inside the browser, where Telegram's service worker answers it. Outside the browser, the server answers 302 with no Location header at all. In rc.15 the probe let that through. Then the chunk request failed on the missing Location, which gives the same "Too many redirects for range request" message as a real loop (chunkDownloader.ts:254 on main). I tested that answer: it fails the same way on main and on this PR. On current main, #177 already refuses it at the probe, and the browser keeps the download, which is what the issue asks for.
So please:
- Remove
Fixes #205, so merging doesn't close the issue. - If you have a real link that needs more than 5 redirects on a range request, please share a
curl -L -vlog or a HAR. Then this makes sense, andMAX_REDIRECTSinprobe.ts(still 5) should go up too. - Optional, but it would really help: give a missing
Locationits own message inchunkDownloader.ts, like "The server sent a redirect with no address to follow".
I also checked that a redirect loop still ends as an error (now after 20 hops), and that cookies and basic auth are still worked out again for each hop's host.
| const MAX_REDIRECTS = 5 | ||
| // Some download hosts use several redirects before serving a chunk. Keep a generous finite cap | ||
| // so those chains work while redirect loops still end as an error. | ||
| const MAX_REDIRECTS = 20 |
There was a problem hiding this comment.
The probe still allows only 5 (probe.ts:19), and chunks start from the probe's final URL. So 20 only helps a server that starts redirecting again on ranges after byte 0. Do you know a real host that does this? If this stays, please use one shared limit for both.
A 302 with no Location is what a Telegram Web link answers outside the browser, and the probe already refuses it before a download starts. When one reaches a chunk request anyway, the shared branch reported it as "Too many redirects for range request", which blamed a redirect budget the response never spent. It now says "The server sent a redirect with no address to follow", and only a chain that actually runs out of hops still reports the limit. The MAX_REDIRECTS increase is dropped: no link needing more than five hops on a range request was ever demonstrated, so the cap stays at main's 5 and the six-hop E2E case goes with it. The new E2E case drives a chunk request at a 302 with no Location and checks the message, which fails on main. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Arpit-Khandelwal Thanks — you're right, and I accept the diagnosis. Your reproduction matches what the source says. In What I changed in fcf5cb3:
New E2E case in On whether to keep this open: I'd recommend closing it. The diagnostic is a genuine small improvement, but it was a side note on a disproved premise, it touches a download error path for a case the probe now stops earlier, and you can land the one-line message in main directly if you want it — so it doesn't need a PR of its own. Your call; I'll close it rather than force it if you'd prefer that. |
Summary
Refs #205.
A Telegram Web link (
web.telegram.org/k/d/...) answers302with noLocationheader outside the browser, and current main already refuses that at the probe, so this PR does not fix #205. The redirect-chain premise is withdrawn:MAX_REDIRECTSstays at main's 5, and the six-hop E2E case that came with the increase is removed. No link needing more than five redirects on a range request was demonstrated, so the cap is not raised without evidence.What is left is the diagnostic the reviewer suggested. When a redirect with no
Locationreaches a chunk request, it used to report "Too many redirects for range request", blaming a redirect budget the response never spent. It now reports:A chain that genuinely runs out of hops still reports the redirect limit.
Validation
e2e/download.spec.ts): a chunk request answered302with noLocationreports the new message and not the redirect limit. Verified it fails against the pre-fixchunkDownloader.tsand passes after.e2e/download.spec.ts+e2e/probeRedirects.spec.ts: 37 passed, 1 skipped.tsc -p tsconfig.e2e.jsonandtsc --noEmit -p tsconfig.node.json: clean.eslinton both changed files: 0 errors.prettier --check: the two changed files pass on LF-normalized content; the Windows checkout reports line-ending warnings across the tree (core.autocrlf=true).