Skip to content

Commit

Permalink
support HTTP Vary header
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Kozjak <kozjakm1@gmail.com>
  • Loading branch information
mkozjak committed May 5, 2017
1 parent 5dd6a87 commit 2ccab8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,28 @@ class Cache {
// return cached response
let requestKeyHeaders, requestKeyBody

if (that.options.vary)
for (let o of that.options.vary)
this.response.vary(o)
else
this.response.vary('Accept-Encoding')

let mod = '%'

for (let o of this.response.headers.vary.split(','))
mod += this.request.get(o.trim().toLowerCase())

if ('undefined' !== typeof that.routes[cacheKey].cacheKeyPrefix) {
requestKeyHeaders = that.routes[cacheKey].cacheKeyPrefix + ':' + requestKey + ':headers'
requestKeyBody = that.routes[cacheKey].cacheKeyPrefix + ':' + requestKey + ':body'
requestKeyHeaders = that.routes[cacheKey].cacheKeyPrefix + ':' + requestKey + ':headers' + mod
requestKeyBody = that.routes[cacheKey].cacheKeyPrefix + ':' + requestKey + ':body' + mod
}
else if ('undefined' !== typeof that.options.cacheKeyPrefix) {
requestKeyHeaders = that.options.cacheKeyPrefix + ':' + requestKey + ':headers'
requestKeyBody = that.options.cacheKeyPrefix + ':' + requestKey + ':body'
requestKeyHeaders = that.options.cacheKeyPrefix + ':' + requestKey + ':headers' + mod
requestKeyBody = that.options.cacheKeyPrefix + ':' + requestKey + ':body' + mod
}
else {
requestKeyHeaders = requestKey + ':headers'
requestKeyBody = requestKey + ':body'
requestKeyHeaders = requestKey + ':headers' + mod
requestKeyBody = requestKey + ':body' + mod
}

let exists = yield that.store.has(requestKeyHeaders)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Mario Kozjak",
"email": "kozjakm1@gmail.com"
},
"version": "3.6.2",
"version": "3.7.0",
"main": "index.js",
"engines": { "iojs": ">= 2.1.0", "node": ">= 4.0.0" },
"license": "MIT",
Expand Down

0 comments on commit 2ccab8b

Please sign in to comment.