Comparing version 0.0.5 to 0.0.6
/// <reference types="node" /> | ||
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'; | ||
/** | ||
* Check freshness of the response using request and response headers. | ||
*/ | ||
export default function fresh(reqHeaders: IncomingHttpHeaders, resHeaders: OutgoingHttpHeaders): boolean; | ||
declare function fresh(reqHeaders: IncomingHttpHeaders, resHeaders: OutgoingHttpHeaders): boolean; | ||
export default fresh; |
@@ -1,61 +0,1 @@ | ||
const CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/; | ||
const parseHttpDate = Date.parse; | ||
const compareETags = (etag, str) => str === etag || str === `W/${etag}` || `W/${str}` === etag; | ||
function isStale(etag, noneMatch) { | ||
let start = 0; | ||
let end = 0; | ||
for (let i = 0, len = noneMatch.length; i < len; i++) { | ||
switch (noneMatch.charCodeAt(i)) { | ||
case 0x20 /* */: | ||
if (start === end) | ||
start = end = i + 1; | ||
break; | ||
case 0x2c /* , */: | ||
if (compareETags(etag, noneMatch.substring(start, end))) | ||
return false; | ||
start = end = i + 1; | ||
break; | ||
default: | ||
end = i + 1; | ||
break; | ||
} | ||
} | ||
if (compareETags(etag, noneMatch.substring(start, end))) | ||
return false; | ||
return true; | ||
} | ||
/** | ||
* Check freshness of the response using request and response headers. | ||
*/ | ||
function fresh(reqHeaders, resHeaders) { | ||
// fields | ||
const modifiedSince = reqHeaders['if-modified-since']; | ||
const noneMatch = reqHeaders['if-none-match']; | ||
// unconditional request | ||
if (!modifiedSince && !noneMatch) | ||
return false; | ||
// Always return stale when Cache-Control: no-cache | ||
// to support end-to-end reload requests | ||
// https://tools.ietf.org/html/rfc2616#section-14.9.4 | ||
const cacheControl = reqHeaders['cache-control']; | ||
if (cacheControl && CACHE_CONTROL_NO_CACHE_REGEXP.test(cacheControl)) { | ||
return false; | ||
} | ||
// if-none-match | ||
if (noneMatch && noneMatch !== '*') { | ||
const etag = resHeaders.etag; | ||
if (!etag || isStale(etag, noneMatch)) | ||
return false; | ||
} | ||
// if-modified-since | ||
if (modifiedSince) { | ||
const lastModified = resHeaders['last-modified']; | ||
if (!lastModified || | ||
!(parseHttpDate(lastModified) <= parseHttpDate(modifiedSince))) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export default fresh; | ||
const CACHE_CONTROL_NO_CACHE_REGEXP=/(?:^|,)\s*?no-cache\s*?(?:,|$)/;const parseHttpDate=Date.parse;const compareETags=(etag,str)=>str===etag||str===`W/${etag}`||`W/${str}`===etag;function isStale(etag,noneMatch){let start=0;let end=0;for(let i=0,len=noneMatch.length;i<len;i++){switch(noneMatch.charCodeAt(i)){case 32:if(start===end)start=end=i+1;break;case 44:if(compareETags(etag,noneMatch.substring(start,end)))return!1;start=end=i+1;break;default:end=i+1;break}}if(compareETags(etag,noneMatch.substring(start,end)))return!1;return!0}function fresh(reqHeaders,resHeaders){const modifiedSince=reqHeaders["if-modified-since"];const noneMatch=reqHeaders["if-none-match"];if(!modifiedSince&&!noneMatch)return!1;const cacheControl=reqHeaders["cache-control"];if(cacheControl&&CACHE_CONTROL_NO_CACHE_REGEXP.test(cacheControl)){return!1}if(noneMatch&&noneMatch!=="*"){const etag=resHeaders.etag;if(!etag||isStale(etag,noneMatch))return!1}if(modifiedSince){const lastModified=resHeaders["last-modified"];if(!lastModified||!(parseHttpDate(lastModified)<=parseHttpDate(modifiedSince))){return!1}}return!0}export{fresh as default}; |
{ | ||
"name": "es-fresh", | ||
"description": "fresh rewrite in TypeScript with ESM and CommonJS targets", | ||
"version": "0.0.5", | ||
"repository": "https://github.com/talentlessguy/es-fresh.git", | ||
"engines": { | ||
"node": ">=12.x" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"author": "talentlessguy <pilll.PL22@gmail.com>", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./package.json": "./package.json", | ||
"./": "./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.0.23", | ||
"rollup": "^2.22.0", | ||
"rollup-plugin-typescript2": "^0.27.1", | ||
"typescript": "^3.9.7" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"prepare": "pnpm build" | ||
} | ||
"name": "es-fresh", | ||
"description": "fresh rewrite in TypeScript with ESM and CommonJS targets", | ||
"version": "0.0.6", | ||
"repository": "https://github.com/talentlessguy/es-fresh.git", | ||
"engines": { | ||
"node": ">=12.x" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"author": "talentlessguy <pilll.PL22@gmail.com>", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./package.json": "./package.json", | ||
"./": "./" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.6.0", | ||
"tsup": "^3.6.1", | ||
"typescript": "^4.0.2" | ||
}, | ||
"scripts": { | ||
"prepare": "pnpm build", | ||
"build": "tsup src/index.ts --minify-whitespace --format cjs,esm --dts" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
8814
78