MCPcopy Create free account
hub / github.com/ascorbic/astro-loaders / getConditionalHeaders

Function getConditionalHeaders

packages/utils/src/index.ts:7–25  ·  view source on GitHub ↗
({
  init,
  meta,
}: {
  /** Initial headers to include */
  init?: RequestInit["headers"];
  /** Meta store to get etag and last-modified values from */
  meta: LoaderContext["meta"];
})

Source from the content-addressed store, hash-verified

5 * Uses the etag and last-modified values from the meta store.
6 */
7export function getConditionalHeaders({
8 init,
9 meta,
10}: {
11 /** Initial headers to include */
12 init?: RequestInit["headers"];
13 /** Meta store to get etag and last-modified values from */
14 meta: LoaderContext["meta"];
15}): Headers {
16 const etag = meta.get("etag");
17 const lastModified = meta.get("last-modified");
18 const headers = new Headers(init);
19 if (etag) {
20 headers.set("If-None-Match", etag);
21 } else if (lastModified) {
22 headers.set("If-Modified-Since", lastModified);
23 }
24 return headers;
25}
26
27/**
28 * Store the etag or last-modified headers from a response in the meta store.

Callers 2

makeYouTubeAPIRequestFunction · 0.85
fetchAndParseFeedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected