Lengthen cache ttl on 404s
This commit is contained in:
		| @ -94,26 +94,24 @@ function searchEntries(tarballStream, entryName, wantsIndex) { | ||||
|  | ||||
|         const chunks = []; | ||||
|  | ||||
|         stream | ||||
|           .on('data', chunk => chunks.push(chunk)) | ||||
|           .on('end', () => { | ||||
|             const content = Buffer.concat(chunks); | ||||
|         stream.on('data', chunk => chunks.push(chunk)).on('end', () => { | ||||
|           const content = Buffer.concat(chunks); | ||||
|  | ||||
|             // Set some extra properties for files that we will | ||||
|             // need to serve them and for ?meta listings. | ||||
|             entry.contentType = getContentType(entry.name); | ||||
|             entry.integrity = getIntegrity(content); | ||||
|             entry.lastModified = header.mtime.toUTCString(); | ||||
|             entry.size = content.length; | ||||
|           // Set some extra properties for files that we will | ||||
|           // need to serve them and for ?meta listings. | ||||
|           entry.contentType = getContentType(entry.name); | ||||
|           entry.integrity = getIntegrity(content); | ||||
|           entry.lastModified = header.mtime.toUTCString(); | ||||
|           entry.size = content.length; | ||||
|  | ||||
|             // Set the content only for the foundEntry and | ||||
|             // discard the buffer for all others. | ||||
|             if (entry === foundEntry) { | ||||
|               entry.content = content; | ||||
|             } | ||||
|           // Set the content only for the foundEntry and | ||||
|           // discard the buffer for all others. | ||||
|           if (entry === foundEntry) { | ||||
|             entry.content = content; | ||||
|           } | ||||
|  | ||||
|             next(); | ||||
|           }); | ||||
|           next(); | ||||
|         }); | ||||
|       }); | ||||
|   }); | ||||
| } | ||||
| @ -139,6 +137,10 @@ export default function findFile(req, res, next) { | ||||
|         if (!foundEntry) { | ||||
|           return res | ||||
|             .status(404) | ||||
|             .set({ | ||||
|               'Cache-Control': 'public, max-age=31536000', // 1 year | ||||
|               'Cache-Tag': 'missing, missing-entry' | ||||
|             }) | ||||
|             .type('text') | ||||
|             .send(`Cannot find "${req.filename}" in ${req.packageSpec}`); | ||||
|         } | ||||
| @ -158,6 +160,10 @@ export default function findFile(req, res, next) { | ||||
|           } else { | ||||
|             return res | ||||
|               .status(404) | ||||
|               .set({ | ||||
|                 'Cache-Control': 'public, max-age=31536000', // 1 year | ||||
|                 'Cache-Tag': 'missing, missing-index' | ||||
|               }) | ||||
|               .type('text') | ||||
|               .send( | ||||
|                 `Cannot find an index in "${req.filename}" in ${ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user