Skip to content

Commit

Permalink
fix: avoid false-positive on too big range end
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored and brunoimbrizi committed May 30, 2023
1 parent 7ee16a8 commit 24ccaee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/middleware.ts
Expand Up @@ -180,12 +180,16 @@ function sendStatic(
if (req.headers.range) {
code = 206
const [x, y] = req.headers.range.replace('bytes=', '').split('-')
const end = (y ? parseInt(y, 10) : 0) || stats.size - 1
let end = (y ? parseInt(y, 10) : 0) || stats.size - 1
const start = (x ? parseInt(x, 10) : 0) || 0
opts.end = end
opts.start = start

if (start >= stats.size || end >= stats.size) {
if (end >= stats.size) {
end = stats.size - 1
}

if (start >= stats.size) {
res.setHeader('Content-Range', `bytes */${stats.size}`)
res.statusCode = 416
res.end()
Expand Down

0 comments on commit 24ccaee

Please sign in to comment.