11import { getStatusCode } from "@readme/http-status-codes" ;
22import { eq } from "drizzle-orm" ;
3+ import { cache } from "react" ;
34import { IMPORTANT_HEADERS } from "@/lib/constants/headers" ;
45import { db } from "@/lib/db/client" ;
56import { findDomainByName } from "@/lib/db/repos/domains" ;
@@ -11,7 +12,14 @@ import { fetchWithSelectiveRedirects } from "@/lib/fetch";
1112import { scheduleSectionIfEarlier } from "@/lib/schedule" ;
1213import type { HttpHeader , HttpHeadersResponse } from "@/lib/schemas" ;
1314
14- export async function probeHeaders (
15+ /**
16+ * Probe HTTP headers for a domain with Postgres caching.
17+ *
18+ * Wrapped in React's cache() for per-request deduplication during SSR,
19+ * ensuring multiple components can query headers without triggering
20+ * multiple HTTP requests to the target domain.
21+ */
22+ export const probeHeaders = cache ( async function probeHeaders (
1523 domain : string ,
1624) : Promise < HttpHeadersResponse > {
1725 const url = `https://${ domain } /` ;
@@ -134,7 +142,7 @@ export async function probeHeaders(
134142 // Return empty on failure without caching to avoid long-lived negatives
135143 return { headers : [ ] , status : 0 , statusMessage : undefined } ;
136144 }
137- }
145+ } ) ;
138146
139147function normalize ( h : HttpHeader [ ] ) : HttpHeader [ ] {
140148 // Normalize header names (trim + lowercase) then sort important first
0 commit comments