Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Oct 18, 2024
1 parent ab2d8dd commit 5ceba5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ module.exports = (opts = {}) => {
methods
}

const safeMethodsToNotCache = util.safeHTTPMethods.filter(method => methods.includes(method) === false)

return dispatch => {
return (opts, handler) => {
if (!opts.origin || (util.safeHTTPMethods.includes(opts.method) && !methods.includes(opts.method))) {
if (!opts.origin || safeMethodsToNotCache.includes(opts.method)) {
// Not a method we want to cache or we don't have the origin, skip
return dispatch(opts, handler)
}
Expand Down
18 changes: 11 additions & 7 deletions test/interceptors/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,17 @@ describe('Cache Interceptor', () => {

strictEqual(deleteByOriginCalled, false)

// Make sure unsafe methods cause a cache purge
await client.request({
origin: 'localhost',
method: 'DELETE',
path: '/'
})
// Make sure the common unsafe methods cause cache purges
for (const method of ['POST', 'PUT', 'PATCH', 'DELETE']) {
deleteByOriginCalled = false

await client.request({
origin: 'localhost',
method,
path: '/'
})

equal(deleteByOriginCalled, true)
equal(deleteByOriginCalled, true, method)
}
})
})

0 comments on commit 5ceba5e

Please sign in to comment.