Skip to content

Commit

Permalink
On revalidation return 304 status to user but don't store it in the c…
Browse files Browse the repository at this point in the history
…ache

e.g If we have a 200 response cached and then geta 304 on revalidate, we should return the 304 status code to the user on that request but subsequent requests that hit the cache should have a status code of 200.
  • Loading branch information
lukechilds committed Jun 10, 2017
1 parent cc9cb9c commit 8cdab0f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const cacheableRequest = (request, cache) => (opts, cb) => {
const revalidatedPolicy = CachePolicy.fromObject(opts._revalidate.cachePolicy).revalidatedPolicy(opts, response);
if (!revalidatedPolicy.modified) {
const headers = revalidatedPolicy.policy.responseHeaders();
response = new Response(opts._revalidate.statusCode, headers, opts._revalidate.body, opts._revalidate.url);
response = new Response(response.statusCode, headers, opts._revalidate.body, opts._revalidate.url);
response.cachePolicy = revalidatedPolicy.policy;
response.fromCache = true;
}
Expand All @@ -52,7 +52,7 @@ const cacheableRequest = (request, cache) => (opts, cb) => {
const value = {
cachePolicy: response.cachePolicy.toObject(),
url: response.url,
statusCode: response.statusCode,
statusCode: response.fromCache ? opts._revalidate.statusCode : response.statusCode,
body
};
const ttl = response.cachePolicy.timeToLive();
Expand Down

0 comments on commit 8cdab0f

Please sign in to comment.