Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

fix: ask for ranges again after a redirect (#167)

Anzy4397c764ef7f
diff --git a/e2e/probeRedirects.spec.ts b/e2e/probeRedirects.spec.ts
index a128628..2fe0800 100644
--- a/e2e/probeRedirects.spec.ts
+++ b/e2e/probeRedirects.spec.ts
@@ -17,6 +17,23 @@ test.describe('probe redirect limits @smoke', () => {
})
}
+ test('a redirect after a refused range still finds a range-capable file', async ({
+ plexo,
+ serve
+ }) => {
+ const origin = await serve({ size: 3 * BLOCK })
+ origin.setRule(({ path, range }) => {
+ if (path === '/signed') return range ? { status: 403 } : { redirect: '/file' }
+ return 'ok'
+ })
+ const result = await plexo.api.probeUrl(origin.url('/signed'))
+ expect(result.kind).toBe('http')
+ if (result.kind !== 'http') throw new Error('Expected HTTP probe')
+ expect(result.finalUrl).toBe(origin.url('/file'))
+ expect(result.totalBytes).toBe(3 * BLOCK)
+ expect(result.supportsRanges).toBe(true)
+ })
+
for (const path of ['/hop/6', '/loop']) {
test(`${path} rejects redirect exhaustion before offering a download`, async ({
plexo,
diff --git a/src/main/download/probe.ts b/src/main/download/probe.ts
index deccb01..f1103d2 100644
--- a/src/main/download/probe.ts
+++ b/src/main/download/probe.ts
@@ -99,8 +99,8 @@ async function requestFollowingRedirects(
let response: ProbeResponse | null = null
const deadline = Date.now() + PROBE_TIMEOUT_MS
- let ranged = true
for (let redirect = 0; redirect <= MAX_REDIRECTS; redirect += 1) {
+ let ranged = true
response = await requestFirstBytes(current, deadline, browser, ranged)
// Some servers refuse any Range request with 403 while serving the same URL in full (#131).
// Ask once more without one: if that works, the file downloads as one stream from byte zero,