diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-01-23 12:18:08 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-01-23 12:18:08 -0500 |
commit | dc008e9096b97befaeba9eb684dbcd8d872c2a38 (patch) | |
tree | 9fe9076351b732120b9f3421d369f23cf7e213fc /lib/serve.js | |
parent | 1eeb202272fd2411123b980aa782f457c6835d76 (diff) | |
parent | 283e57119d86f442bc6184ae26303b9cd1b9e0e8 (diff) | |
download | patchfoo-dc008e9096b97befaeba9eb684dbcd8d872c2a38.tar.gz patchfoo-dc008e9096b97befaeba9eb684dbcd8d872c2a38.zip |
Merge branch 'main' into evmik-logbook-next
Diffstat (limited to 'lib/serve.js')
-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 7237a88..b61505b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -2131,6 +2131,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) { @@ -2150,7 +2157,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 |