Fix handling of 206 status code in updater
This commit is contained in:
parent
c8842d94ec
commit
0a24ca8d88
2 changed files with 15 additions and 10 deletions
|
@ -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') {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue