diff --git a/ts/test-node/updater/differential_test.ts b/ts/test-node/updater/differential_test.ts index e25c936b3..b594ae89a 100644 --- a/ts/test-node/updater/differential_test.ts +++ b/ts/test-node/updater/differential_test.ts @@ -112,7 +112,7 @@ describe('updater/differential', () => { }); if (ranges.length === 1) { - res.writeHead(200, { + res.writeHead(206, { 'content-type': 'application/octet-stream', }); if (shouldTimeout === 'response') { diff --git a/ts/updater/differential.ts b/ts/updater/differential.ts index 78e7169d8..7acff7182 100644 --- a/ts/updater/differential.ts +++ b/ts/updater/differential.ts @@ -386,8 +386,14 @@ export async function downloadRanges( 'response' ); - // When the result is single range we might get 200 status code - if (ranges.length === 1 && statusCode === 200) { + strictAssert(statusCode === 206, `Invalid status code: ${statusCode}`); + + const match = headers['content-type']?.match( + /^multipart\/byteranges;\s*boundary=([^\s;]+)/ + ); + + // When the result is single range we might non-multipart response + if (ranges.length === 1 && !match) { await saveDiffStream({ diff: ranges[0], stream, @@ -398,13 +404,6 @@ export async function downloadRanges( return; } - strictAssert(statusCode === 206, `Invalid status code: ${statusCode}`); - - const match = headers['content-type']?.match( - /^multipart\/byteranges;\s*boundary=([^\s;]+)/ - ); - strictAssert(match, `Invalid Content-Type: ${headers['content-type']}`); - // eslint-disable-next-line prefer-destructuring boundary = match[1]; } catch (error) { @@ -511,6 +510,12 @@ async function saveDiffStream({ await output.write(chunk, 0, chunk.length, offset + diff.writeOffset); offset += chunk.length; + // Check for signal again so that we don't invoke status callback when + // aborted. + if (abortSignal?.aborted) { + return; + } + chunkStatusCallback(chunk.length); }