-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return no-cache on 404 #2609
return no-cache on 404 #2609
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,16 @@ const route = new Proxy({}, { | |
} | ||
}) | ||
|
||
// helper function that returns 404 and prevents client from caching the 404 response | ||
// which can sometimes break things: https://github.com/okTurtles/group-income/issues/2608 | ||
function notFoundNoCache (h) { | ||
return h.response() | ||
.code(404) | ||
.header('Cache-Control', 'no-store, must-revalidate, proxy-revalidate') | ||
.header('Pragma', 'no-cache') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.header('Expires', '0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// RESTful API routes | ||
|
||
// TODO: Update this regex once `chel` uses prefixed manifests | ||
|
@@ -277,7 +287,7 @@ route.GET('/latestHEADinfo/{contractID}', { | |
const HEADinfo = await sbp('chelonia/db/latestHEADinfo', contractID) | ||
if (!HEADinfo) { | ||
console.warn(`[backend] latestHEADinfo not found for ${contractID}`) | ||
return Boom.notFound() | ||
return notFoundNoCache(h) | ||
} | ||
return HEADinfo | ||
} catch (err) { | ||
|
@@ -473,7 +483,7 @@ route.GET('/file/{hash}', { | |
|
||
const blobOrString = await sbp('chelonia/db/get', `any:${hash}`) | ||
if (!blobOrString) { | ||
return Boom.notFound() | ||
return notFoundNoCache(h) | ||
} | ||
return h.response(blobOrString).etag(hash) | ||
}) | ||
|
@@ -675,7 +685,7 @@ route.GET('/kv/{contractID}/{key}', { | |
|
||
const result = await sbp('chelonia/db/get', `_private_kv_${contractID}_${key}`) | ||
if (!result) { | ||
return Boom.notFound() | ||
return notFoundNoCache(h) | ||
} | ||
|
||
return h.response(result).etag(createCID(result)) | ||
|
@@ -804,7 +814,7 @@ route.GET('/zkpp/{name}/auth_hash', { | |
try { | ||
const challenge = await getChallenge(req.params['name'], req.query['b']) | ||
|
||
return challenge || Boom.notFound() | ||
return challenge || notFoundNoCache(h) | ||
} catch (e) { | ||
e.ip = req.headers['x-real-ip'] || req.info.remoteAddress | ||
console.error(e, 'Error at GET /zkpp/{name}/auth_hash: ' + e.message) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*-revalidate
is redundant as well, sinceno-store
already means that the response should not be put in a cache to begin with.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think the issue here is this, since by default 404 responses will not be cached.
I'm not too familiar with HAPI, and not with the old version used in GI, but, instead of setting a cache policy and then 'undoing it' with this new
notFoundNoCache
wouldn't it be better to simply tell HAPI not to apply theimmutable
(or a custom) cache policy to errors?