3 changed files with 16 additions and 16 deletions
@ -1,19 +1,19 @@ |
|||||
const addSeconds = require('date-fns/add_seconds') |
const addSeconds = require('date-fns/add_seconds'); |
||||
|
|
||||
function expired (headers) { |
function expired(headers) { |
||||
const originDate = new Date(headers.date) |
const originDate = new Date(headers.date); |
||||
|
|
||||
// Get max age ms
|
// Get max age ms
|
||||
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/) |
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/); |
||||
maxAge = parseInt(maxAge ? maxAge[1] : 0) |
maxAge = parseInt(maxAge ? maxAge[1] : 0, 10); |
||||
|
|
||||
// Take current age into account
|
// Take current age into account
|
||||
if (headers.age) { |
if (headers.age) { |
||||
maxAge -= headers.age |
maxAge -= headers.age; |
||||
} |
} |
||||
|
|
||||
// Calculate expirey date
|
// Calculate expirey date
|
||||
return addSeconds(new Date(originDate), maxAge) |
return addSeconds(new Date(originDate), maxAge); |
||||
} |
} |
||||
|
|
||||
module.exports = expired |
module.exports = expired; |
||||
|
@ -1,6 +1,6 @@ |
|||||
import test from 'ava' |
import test from 'ava'; |
||||
import expired from '../' |
import expired from '../'; |
||||
|
|
||||
test('expired is a function', t => { |
test('expired is a function', t => { |
||||
t.is(typeof expired, 'function') |
t.is(typeof expired, 'function'); |
||||
}) |
}); |
||||
|
Loading…
Reference in new issue