MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / safeFetch

Function safeFetch

packages/cli/src/capture/assetDownloader.ts:346–364  ·  view source on GitHub ↗
(url: string, init?: RequestInit)

Source from the content-addressed store, hash-verified

344 * or on network error.
345 */
346export async function safeFetch(url: string, init?: RequestInit): Promise<Response | null> {
347 let current = url;
348 for (let hop = 0; hop <= MAX_FETCH_REDIRECTS; hop++) {
349 if (isPrivateUrl(current)) return null;
350 const res = await fetch(current, { ...init, redirect: "manual" });
351 if (res.status >= 300 && res.status < 400) {
352 const loc = res.headers.get("location");
353 if (!loc) return res;
354 try {
355 current = new URL(loc, current).toString();
356 } catch {
357 return null; // malformed Location header
358 }
359 continue;
360 }
361 return res;
362 }
363 return null; // too many redirects
364}
365
366async function fetchBuffer(url: string): Promise<Buffer | null> {
367 try {

Callers 5

streamToFileFunction · 0.85
saveLottieAnimationsFunction · 0.85
downloadVideoBodyFunction · 0.85
fetchBufferFunction · 0.85

Calls 3

isPrivateUrlFunction · 0.85
fetchFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected