tickle/modules/utils/fetchHeaders.mjs

23 lines
439 B
JavaScript
Raw Permalink Normal View History

2023-06-06 22:45:16 +00:00
//@ts-check
/**
* Limited fetch request that retrieves only headers.
* @param {string} path
*/
export const fetchHeaders = async (path) => {
const response = await fetch(path, {
method: "HEAD",
headers: {
Range: "bytes=0-0",
"X-HTTP-Method-Override": "HEAD",
},
});
if (!response.ok) {
throw new Error(`Failed loading file '${path}'`);
}
return response.headers;
};
export default fetchHeaders;