Skip to content

Commit f21ee03

Browse files
committed
Expose response status
1 parent f01112e commit f21ee03

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,13 @@ module.exports = class CachePolicy {
334334

335335
/**
336336
* @param {{headers: Record<string, string>, synchronous: boolean}|undefined} revalidation - Revalidation information, if any.
337-
* @returns {{response: {headers: Record<string, string>}, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object with a cached response headers and revalidation info.
337+
* @returns {{response: HttpResponse, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object with a cached response headers and revalidation info.
338338
*/
339339
_evaluateRequestHitResult(revalidation) {
340340
return {
341341
response: {
342342
headers: this.responseHeaders(),
343+
status: this._status,
343344
},
344345
revalidation,
345346
};
@@ -387,9 +388,9 @@ module.exports = class CachePolicy {
387388
* }
388389
* ```
389390
* @param {HttpRequest} req - new incoming HTTP request
390-
* @returns {{response: {headers: Record<string, string>}|undefined, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object containing keys:
391+
* @returns {{response: HttpResponse|undefined, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object containing keys:
391392
* - revalidation: { headers: Record<string, string>, synchronous: boolean } Set if you should send this to the origin server
392-
* - response: { headers: Record<string, string> } Set if you can respond to the client with these cached headers
393+
* - response: HttpResponse Set if you can respond to the client with these cached headers
393394
*/
394395
evaluateRequest(req) {
395396
this._assertRequestHasHeaders(req);
@@ -556,6 +557,14 @@ module.exports = class CachePolicy {
556557
return headers;
557558
}
558559

560+
/**
561+
* Returns the status code of the cached response.
562+
* @returns {number} The response status code.
563+
*/
564+
status() {
565+
return this._status;
566+
}
567+
559568
/**
560569
* Returns the Date header value from the response or the current time if invalid.
561570
* @returns {number} Timestamp (in milliseconds) representing the Date header or response time.

0 commit comments

Comments
 (0)