Skip to content

Commit

Permalink
fix(sirv): use "no-store" when dev & etag enabled;
Browse files Browse the repository at this point in the history
- Closes #90
  • Loading branch information
lukeed committed Dec 7, 2020
1 parent 2597417 commit c8fe11b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/sirv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function viaLocal(dir, isEtag, uri, extns) {
stats = fs.statSync(abs);
if (stats.isDirectory()) continue;
headers = toHeaders(name, stats, isEtag);
headers['Cache-Control'] = 'no-store';
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
return { abs, stats, headers };
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/sirv.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ dev('should not rely on file cached data', async () => {
}
});

dev('should set default `Cache-Control` header value', async () => {
let server = utils.http({ dev: true });

try {
let res1 = await server.send('GET', '/bundle.67329.js');
assert.is(res1.headers['cache-control'], 'no-store');
} finally {
server.close();
}
});

dev.run();

// ---
Expand Down Expand Up @@ -648,6 +659,22 @@ etag('should allow "If-None-Match" directive to function', async () => {
}
});

etag('should force `Cache-Control` header in `dev` mode', async () => {
let server = utils.http({ etag: true, dev: true });

try {
let res1 = await server.send('GET', '/bundle.67329.js');
assert.is(res1.headers['cache-control'], 'no-cache');

let headers = { 'If-None-Match': res1.headers['etag'] };
let res2 = await server.send('GET', '/bundle.67329.js', { headers });
assert.is(res2.statusCode, 304, 'send 304 for "no change" signal');
assert.is(res2.data, '', 'send empty response body');
} finally {
server.close();
}
});

etag.run();

// ---
Expand Down

0 comments on commit c8fe11b

Please sign in to comment.