({
init,
meta,
}: {
/** Initial headers to include */
init?: RequestInit["headers"];
/** Meta store to get etag and last-modified values from */
meta: LoaderContext["meta"];
})
| 5 | * Uses the etag and last-modified values from the meta store. |
| 6 | */ |
| 7 | export 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. |
no outgoing calls
no test coverage detected