diff --git a/flaska.mjs b/flaska.mjs index 796f1b0..33958e7 100644 --- a/flaska.mjs +++ b/flaska.mjs @@ -290,6 +290,8 @@ export class HttpError extends Error { } } +const RangeRegexTester = /bytes=(\d+)-(\d+)?/ + export class FileResponse { constructor(filepath, stat) { this.filepath = filepath @@ -333,7 +335,8 @@ export class FileResponse { let size = this.stat.size if (ctx.req.headers['range']) { - let match = ctx.req.headers['range'].match(/bytes=(\d+)-(\d+)?/) + let match = RangeRegexTester.exec(ctx.req.headers['range']) + let ifRange = ctx.req.headers['if-range'] if (ifRange) { if (ifRange[0] === '"' && ifRange !== etag) { @@ -345,6 +348,7 @@ export class FileResponse { } } } + if (match) { let start = Number(match[1]) let end = size - 1 diff --git a/package.json b/package.json index 581a749..6b75325 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flaska", - "version": "1.1.0", + "version": "1.1.1", "description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.", "main": "flaska.mjs", "scripts": {