diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2021-01-05 07:46:12 -0500 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2021-01-05 07:46:12 -0500 |
commit | 995c0fbf37398ddeafe6eddc7b61137090601b3a (patch) | |
tree | 34f269f7376170b051522d3af4bee6778a88666e | |
parent | 000ee106a73347a888eae87e6a1585383b5f7698 (diff) | |
download | patchfoo-995c0fbf37398ddeafe6eddc7b61137090601b3a.tar.gz patchfoo-995c0fbf37398ddeafe6eddc7b61137090601b3a.zip |
Fix serving boxed blob with range request
- Fix error handling
- Calculate size of unboxed blob
-rw-r--r-- | lib/serve.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js index a06f566..a9a3691 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -2101,6 +2101,13 @@ Serve.prototype.blob = function (id, path) { if (/^invalid/.test(err.message)) return self.respond(400, err.message) else return self.respond(500, err.message || err) } + if (key) { + // Transform size of boxed blob to size of cleartext. + // Assume that the blob contains box-stream packets that are all full 4096-byte packets except maybe the last one, plus one goodbye packet + // boxedlen = origlen + ceil(origlen / 4096)*34 + 34 + const numBoxHeaders = Math.ceil((size - 34) / 4130) + 1 + size -= numBoxHeaders * 34 + } self.res.setHeader('Accept-Ranges', 'bytes') var range = self.req.headers.range if (range) { @@ -2120,7 +2127,7 @@ Serve.prototype.blob = function (id, path) { start = Number(start) last = Number(last) } - if (start > size || last >= size) return res.writeHead(416, 'Range not satisfiable') + if (start > size || last >= size) return self.respond(416, 'Range not satisfiable') var end = last + 1 var length = end - start var wroteHeaders = false |