Skip to content

Commit

Permalink
feat(http): allow ignoring cache-control header via `ignoreCacheCon…
Browse files Browse the repository at this point in the history
…trol`
  • Loading branch information
pi0 committed Oct 17, 2023
1 parent 6e884b3 commit 4690342
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/storage/http.ts
Expand Up @@ -8,6 +8,7 @@ export type HTTPStorageOptions = {
maxAge?: number;
domains?: string | string[];
allowAllDomains?: boolean;
ignoreCacheControl?: boolean;
};

const HTTP_RE = /^https?:\/\//;
Expand Down Expand Up @@ -59,11 +60,13 @@ export function ipxHttpStorage(_options: HTTPStorageOptions = {}): IPXStorage {
// eslint-disable-next-line unicorn/consistent-function-scoping
function parseResponse(response: Response) {
let maxAge = defaultMaxAge;
const _cacheControl = response.headers.get("cache-control");
if (_cacheControl) {
const m = _cacheControl.match(/max-age=(\d+)/);
if (m && m[1]) {
maxAge = Number.parseInt(m[1]);
if (_options.ignoreCacheControl) {
const _cacheControl = response.headers.get("cache-control");
if (_cacheControl) {
const m = _cacheControl.match(/max-age=(\d+)/);
if (m && m[1]) {
maxAge = Number.parseInt(m[1]);
}
}
}

Expand Down

0 comments on commit 4690342

Please sign in to comment.