Skip to content

Commit 7894244

Browse files
committed
Make clients gracefully handle mismatched 304 responses
https://github.com/lukechilds/cacheable-request/issues/28
1 parent 4b81cac commit 7894244

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ module.exports = class CachePolicy {
488488
if (!matches) {
489489
return {
490490
policy: new this.constructor(request, response),
491-
modified: true,
491+
// Client receiving 304 without body, even if it's invalid/mismatched has no option
492+
// but to reuse a cached body. We don't have a good way to tell clients to do
493+
// error recovery in such case.
494+
modified: response.status != 304,
495+
matches: false,
492496
}
493497
}
494498

@@ -507,6 +511,7 @@ module.exports = class CachePolicy {
507511
return {
508512
policy: new this.constructor(request, newResponse, {shared: this._isShared, cacheHeuristic: this._cacheHeuristic, immutableMinTimeToLive: this._immutableMinTtl, trustServerDate: this._trustServerDate}),
509513
modified: false,
514+
matches: true,
510515
};
511516
}
512517
};

0 commit comments

Comments
 (0)