Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
46 lines
1.2 KiB
Plaintext
46 lines
1.2 KiB
Plaintext
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' || result.length === 0) {
|
|
return {
|
|
type: 'invalid',
|
|
range: null
|
|
};
|
|
}
|
|
// Multi-range requests: use first range only (standard simplification)
|
|
const range = result[0];
|
|
if (!range) {
|
|
return {
|
|
type: 'invalid',
|
|
range: null
|
|
};
|
|
}
|
|
return {
|
|
type: 'partial',
|
|
range: {
|
|
end: range.end,
|
|
start: range.start
|
|
}
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=parseRangeHeader.js.map |