MCPcopy
hub / github.com/tinyhttp/tinyhttp / enableCaching

Function enableCaching

packages/send/src/sendFile.ts:39–45  ·  view source on GitHub ↗
(res: Res, caching: Caching)

Source from the content-addressed store, hash-verified

37type Res = Pick<S, 'setHeader' | 'statusCode' | 'writeHead'> & NodeJS.WritableStream
38
39export const enableCaching = (res: Res, caching: Caching) => {
40 let cc = caching.maxAge != null && `public,max-age=${caching.maxAge}`
41 if (cc && caching.immutable) cc += ',immutable'
42 else if (cc && caching.maxAge === 0) cc += ',must-revalidate'
43
44 res.setHeader('Cache-Control', cc)
45}
46
47/**
48 * Sends a file by piping a stream to response.

Callers 2

sendStreamFunction · 0.90
sendFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected