diff --git a/lib/handler/retry-handler.js b/lib/handler/retry-handler.js index bf8fc0ae1c4..d1dcca8f6c8 100644 --- a/lib/handler/retry-handler.js +++ b/lib/handler/retry-handler.js @@ -229,7 +229,7 @@ class RetryHandler { return false } - const { start, size, end = size } = contentRange + const { start, size, end = size - 1 } = contentRange assert(this.start === start, 'content-range mismatch') assert(this.end == null || this.end === end, 'content-range mismatch') @@ -252,7 +252,7 @@ class RetryHandler { ) } - const { start, size, end = size } = range + const { start, size, end = size - 1 } = range assert( start != null && Number.isFinite(start), 'content-range mismatch' @@ -266,7 +266,7 @@ class RetryHandler { // We make our best to checkpoint the body for further range headers if (this.end == null) { const contentLength = headers['content-length'] - this.end = contentLength != null ? Number(contentLength) : null + this.end = contentLength != null ? Number(contentLength) - 1 : null } assert(Number.isFinite(this.start)) diff --git a/test/interceptors/retry.js b/test/interceptors/retry.js index d13b5966204..2ba1623e86e 100644 --- a/test/interceptors/retry.js +++ b/test/interceptors/retry.js @@ -253,14 +253,15 @@ test('Should handle 206 partial content', async t => { const server = createServer((req, res) => { if (x === 0) { t.ok(true, 'pass') + res.setHeader('content-length', '6') res.setHeader('etag', 'asd') res.write('abc') setTimeout(() => { res.destroy() }, 1e2) } else if (x === 1) { - t.deepStrictEqual(req.headers.range, 'bytes=3-') - res.setHeader('content-range', 'bytes 3-6/6') + t.deepStrictEqual(req.headers.range, 'bytes=3-5') + res.setHeader('content-range', 'bytes 3-5/6') res.setHeader('etag', 'asd') res.statusCode = 206 res.end('def')