Files
klz-cables.com/.pnpm-store/v10/files/fa/a3ff68b5b7bd8f8893e357d99f38604704beeebab561cc64d90da1f94b43bf099d4e30fc879284b8a644c353614a6dec09e39f35a5a2082ffa1b10fcde0344
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

52 lines
1.7 KiB
Plaintext

import { status as httpStatus } from 'http-status';
import { parseRangeHeader } from './parseRangeHeader.js';
/**
* Gets HTTP Range request information according to RFC 7233
*
* @param fileSize - The total size of the file in bytes
* @param rangeHeader - The Range header value from the request (e.g., "bytes=0-1023")
* @returns Result object with headers and status code for the response
*/ export function getRangeRequestInfo({ fileSize, rangeHeader }) {
// Parse the Range header
const rangeResult = parseRangeHeader({
fileSize,
rangeHeader
});
// Handle invalid range
if (rangeResult.type === 'invalid') {
return {
type: 'invalid',
headers: {
'Content-Range': `bytes */${fileSize}`
},
status: httpStatus.REQUESTED_RANGE_NOT_SATISFIABLE
};
}
// Handle partial range request
if (rangeResult.type === 'partial' && rangeResult.range) {
const { end, start } = rangeResult.range;
const contentLength = end - start + 1;
return {
type: 'partial',
headers: {
'Accept-Ranges': 'bytes',
'Content-Length': String(contentLength),
'Content-Range': `bytes ${start}-${end}/${fileSize}`
},
rangeEnd: end,
rangeStart: start,
status: httpStatus.PARTIAL_CONTENT
};
}
// Handle full file request (no range or invalid)
return {
type: 'full',
headers: {
'Accept-Ranges': 'bytes',
'Content-Length': String(fileSize)
},
status: httpStatus.OK
};
}
//# sourceMappingURL=getRangeRequestInfo.js.map