diff --git a/lib/handler/retry-handler.js b/lib/handler/retry-handler.js index e00e82faf08..5d1ccf00538 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 6e6f997cafa..b510ddba6c0 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')