diff --git a/index.js b/index.js index f01e9a1..4de2061 100644 --- a/index.js +++ b/index.js @@ -334,12 +334,13 @@ module.exports = class CachePolicy { /** * @param {{headers: Record, synchronous: boolean}|undefined} revalidation - Revalidation information, if any. - * @returns {{response: {headers: Record}, revalidation: {headers: Record, synchronous: boolean}|undefined}} An object with a cached response headers and revalidation info. + * @returns {{response: HttpResponse, revalidation: {headers: Record, synchronous: boolean}|undefined}} An object with a cached response headers and revalidation info. */ _evaluateRequestHitResult(revalidation) { return { response: { headers: this.responseHeaders(), + status: this._status, }, revalidation, }; @@ -387,9 +388,9 @@ module.exports = class CachePolicy { * } * ``` * @param {HttpRequest} req - new incoming HTTP request - * @returns {{response: {headers: Record}|undefined, revalidation: {headers: Record, synchronous: boolean}|undefined}} An object containing keys: + * @returns {{response: HttpResponse|undefined, revalidation: {headers: Record, synchronous: boolean}|undefined}} An object containing keys: * - revalidation: { headers: Record, synchronous: boolean } Set if you should send this to the origin server - * - response: { headers: Record } Set if you can respond to the client with these cached headers + * - response: HttpResponse Set if you can respond to the client with these cached headers */ evaluateRequest(req) { this._assertRequestHasHeaders(req); @@ -556,6 +557,14 @@ module.exports = class CachePolicy { return headers; } + /** + * Returns the status code of the cached response. + * @returns {number} The response status code. + */ + status() { + return this._status; + } + /** * Returns the Date header value from the response or the current time if invalid. * @returns {number} Timestamp (in milliseconds) representing the Date header or response time.