Browse Source

Account for current age in cache calculations

Otherwise 304 responses get thrown off as they have the orig 200 date with the age set
pull/15/head
Luke Childs 8 years ago
parent
commit
290e877f90
  1. 5
      src/index.js

5
src/index.js

@ -45,6 +45,11 @@ class Onionoo {
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/)
maxAge = parseInt(maxAge ? maxAge[1] : 0)
// Take current age into account
if (headers.age) {
maxAge -= headers.age
}
// Calculate expirey date
return addSeconds(new Date(originDate), maxAge)
}

Loading…
Cancel
Save