Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions e2e/download.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BLOCK, expect, LAN_ADDRESS, test } from './fixtures'
import { isProbe } from './origin'

// A. Downloads that should simply work. Every test also runs the automatic checks in
// fixtures.ts: completed ⇒ the file's SHA-256 matches the source, nothing stray left behind.
Expand Down Expand Up @@ -180,6 +181,21 @@ test.describe('happy paths @smoke', () => {
await plexo.waitForHttpStatus('completed')
expect(redirected).toBeGreaterThan(0)
})

test('a chunk redirect with no Location says so instead of blaming a redirect limit', async ({
plexo,
serve
}) => {
const origin = await serve({ size: 12 * BLOCK })
// What a Telegram Web link answers outside the browser: a 302 with no Location at all.
origin.setRule(({ range }) =>
range && !isProbe(range) ? { status: 302, headers: { 'Content-Length': '0' } } : 'ok'
)
await plexo.start(origin.url(), origin.sha256)
const state = await plexo.waitForHttpStatus('error')
expect(state.error).toMatch(/redirect with no address to follow/)
expect(state.error).not.toMatch(/Too many redirects/)
})
})

test.describe('file names @smoke', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/main/download/chunkDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ export function downloadChunk(options: ChunkDownloadOptions): Promise<void> {

if (status >= 300 && status < 400) {
res.resume()
if (!res.headers.location || redirectsLeft <= 0) {
// A redirect with no Location isn't a chain at all: there is nowhere to go. Said
// apart from a real loop, it points at the server rather than at a redirect budget.
if (!res.headers.location) {
fail(new Error('The server sent a redirect with no address to follow'))
return
}
if (redirectsLeft <= 0) {
fail(new Error('Too many redirects for range request'))
return
}
Expand Down
Loading