@@ -146,7 +146,7 @@ module.exports = (opts = {}) => {
146
146
* @param {import('../../types/cache-interceptor.d.ts').default.GetResult } result
147
147
* @param {number } age
148
148
*/
149
- const respondWithCachedValue = ( { headers, statusCode, statusMessage, body } , age ) => {
149
+ const respondWithCachedValue = ( { headers, statusCode, statusMessage, body } , age , context ) => {
150
150
const stream = util . isStream ( body )
151
151
? body
152
152
: Readable . from ( body ?? [ ] )
@@ -161,6 +161,9 @@ module.exports = (opts = {}) => {
161
161
pause ( ) {
162
162
stream . pause ( )
163
163
} ,
164
+ get paused ( ) {
165
+ return stream . isPaused ( )
166
+ } ,
164
167
get aborted ( ) {
165
168
return stream . destroyed
166
169
} ,
@@ -188,18 +191,15 @@ module.exports = (opts = {}) => {
188
191
}
189
192
} )
190
193
191
- handler . onRequestStart ?. ( controller )
194
+ handler . onRequestStart ?. ( controller , context )
192
195
193
196
if ( stream . destroyed ) {
194
197
return
195
198
}
196
199
197
200
// Add the age header
198
201
// https://www.rfc-editor.org/rfc/rfc9111.html#name-age
199
- headers = {
200
- ...headers ,
201
- age : String ( Math . round ( ( Date . now ( ) - result . cachedAt ) / 1000 ) )
202
- }
202
+ headers = age ? { ...headers , age : String ( age ) } : headers
203
203
204
204
handler . onResponseStart ?. ( controller , statusCode , statusMessage , headers )
205
205
@@ -248,9 +248,9 @@ module.exports = (opts = {}) => {
248
248
}
249
249
} ,
250
250
new CacheRevalidationHandler (
251
- ( success ) => {
251
+ ( success , context ) => {
252
252
if ( success ) {
253
- respondWithCachedValue ( result , age )
253
+ respondWithCachedValue ( result , age , context )
254
254
} else if ( util . isStream ( result . body ) ) {
255
255
result . body . on ( 'error' , ( ) => { } ) . destroy ( )
256
256
}
@@ -264,6 +264,7 @@ module.exports = (opts = {}) => {
264
264
if ( util . isStream ( opts . body ) ) {
265
265
opts . body . on ( 'error' , ( ) => { } ) . destroy ( )
266
266
}
267
+
267
268
respondWithCachedValue ( result , age )
268
269
}
269
270
0 commit comments