fix: Interpret max-age=0 as a valid cache-control header (#253)

* fix: Interpret `max-age=0` as a valid `cache-control` header

* tests: added max-age=0 test

* fix: fixed linting

Co-authored-by: arthurfiorette <arthur.fiorette@gmail.com>
This commit is contained in:
Heiko Rothkranz 2022-06-03 08:57:51 +08:00 committed by GitHub
parent e1d6bdd955
commit 728b69d71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -28,7 +28,7 @@ export const defaultHeaderInterpreter: HeadersInterpreter = (headers) => {
return 0;
}
if (maxAge) {
if (maxAge !== undefined) {
const age = headers[Header.Age];
if (!age) {

View File

@ -30,4 +30,13 @@ describe('test Cache-Control header', () => {
// 10 Seconds in milliseconds
expect(result).toBe(10 * 1000);
});
it('tests with max-age of 0', () => {
const result = defaultHeaderInterpreter({
[Header.CacheControl]: 'max-age=0'
});
expect(result).toBe(0);
expect(result).not.toBe('not enough headers');
});
});