fetchHTML() — astro Function Reference
Architecture documentation for the fetchHTML() function in router.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 5a0af174_e810_2fce_864c_1a4fecf4bc03["fetchHTML()"] 2b5c33e2_176e_e839_f05f_7f10493f4f74["router.ts"] 5a0af174_e810_2fce_864c_1a4fecf4bc03 -->|defined in| 2b5c33e2_176e_e839_f05f_7f10493f4f74 6b23b6bb_d4a4_83cb_3896_2e31c0316793["transition()"] 6b23b6bb_d4a4_83cb_3896_2e31c0316793 -->|calls| 5a0af174_e810_2fce_864c_1a4fecf4bc03 style 5a0af174_e810_2fce_864c_1a4fecf4bc03 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/transitions/router.ts lines 93–122
async function fetchHTML(
href: string,
init?: RequestInit,
): Promise<null | { html: string; redirected?: string; mediaType: DOMParserSupportedType }> {
try {
// Apply adapter-specific headers for internal fetches
const headers = new Headers(init?.headers);
for (const [key, value] of Object.entries(internalFetchHeaders) as [string, string][]) {
headers.set(key, value);
}
const res = await fetch(href, { ...init, headers });
const contentType = res.headers.get('content-type') ?? '';
// drop potential charset (+ other name/value pairs) as parser needs the mediaType
const mediaType = contentType.split(';', 1)[0].trim();
// the DOMParser can handle two types of HTML
if (mediaType !== 'text/html' && mediaType !== 'application/xhtml+xml') {
// everything else (e.g. audio/mp3) will be handled by the browser but not by us
return null;
}
const html = await res.text();
return {
html,
redirected: res.redirected ? res.url : undefined,
mediaType,
};
} catch {
// can't fetch, let someone else deal with it.
return null;
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does fetchHTML() do?
fetchHTML() is a function in the astro codebase, defined in packages/astro/src/transitions/router.ts.
Where is fetchHTML() defined?
fetchHTML() is defined in packages/astro/src/transitions/router.ts at line 93.
What calls fetchHTML()?
fetchHTML() is called by 1 function(s): transition.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free