UNPKG

payload

Version:

Node, React, Headless CMS and Application Framework built on Next.js

52 lines (51 loc) 1.31 kB
import parseRange from 'range-parser'; /** * Parses HTTP Range header according to RFC 7233 * * @returns Result object indicating whether to serve full file, partial content, or invalid range */ export function parseRangeHeader({ fileSize, rangeHeader }) { // No Range header - serve full file if (!rangeHeader) { return { type: 'full', range: null }; } const result = parseRange(fileSize, rangeHeader); // Invalid range syntax or unsatisfiable range if (result === -1 || result === -2) { return { type: 'invalid', range: null }; } // Must be bytes range type if (result.type !== 'bytes') { return { type: 'invalid', range: null }; } // Multi-range requests: use first range only (standard simplification) if (result.length === 0) { return { type: 'invalid', range: null }; } const range = result[0]; if (range) { return { type: 'partial', range: { end: range.end, start: range.start } }; } return { type: 'invalid', range: null }; } //# sourceMappingURL=parseRangeHeader.js.map