UNPKG

bunshine

Version:

A Bun HTTP & WebSocket server that is a little ray of sunshine.

21 lines (18 loc) 582 B
export default function isModifiedSince( request: Request, lastModified: Date ): boolean { const ifModifiedSince = request.headers.get('If-Modified-Since'); if (!ifModifiedSince) { return true; } // Parse the If-Modified-Since header into a Date object const imsDate = new Date(ifModifiedSince); // Check if the parsed date is valid if (isNaN(imsDate.getTime())) { // If the date is invalid, assume the resource has been modified return true; } // Compare the parsed date with the resource's last modified date return lastModified > imsDate; }