Luke Childs
8 years ago
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) { |
|||
const originDate = new Date(headers.date) |
|||
const originDate = new Date(headers.date); |
|||
|
|||
// Get max age ms
|
|||
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/) |
|||
maxAge = parseInt(maxAge ? maxAge[1] : 0) |
|||
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/); |
|||
maxAge = parseInt(maxAge ? maxAge[1] : 0, 10); |
|||
|
|||
// Take current age into account
|
|||
if (headers.age) { |
|||
maxAge -= headers.age |
|||
maxAge -= headers.age; |
|||
} |
|||
|
|||
// 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 expired from '../' |
|||
import test from 'ava'; |
|||
import expired from '../'; |
|||
|
|||
test('expired is a function', t => { |
|||
t.is(typeof expired, 'function') |
|||
}) |
|||
t.is(typeof expired, 'function'); |
|||
}); |
|||
|
Loading…
Reference in new issue