@@ -146,7 +146,7 @@ module.exports = (opts = {}) => {
146146 * @param {import('../../types/cache-interceptor.d.ts').default.GetResult } result
147147 * @param {number } age
148148 */
149- const respondWithCachedValue = ( { headers, statusCode, statusMessage, body } , age ) => {
149+ const respondWithCachedValue = ( { headers, statusCode, statusMessage, body } , age , context ) => {
150150 const stream = util . isStream ( body )
151151 ? body
152152 : Readable . from ( body ?? [ ] )
@@ -161,6 +161,9 @@ module.exports = (opts = {}) => {
161161 pause ( ) {
162162 stream . pause ( )
163163 } ,
164+ get paused ( ) {
165+ return stream . isPaused ( )
166+ } ,
164167 get aborted ( ) {
165168 return stream . destroyed
166169 } ,
@@ -188,18 +191,15 @@ module.exports = (opts = {}) => {
188191 }
189192 } )
190193
191- handler . onRequestStart ?. ( controller )
194+ handler . onRequestStart ?. ( controller , context )
192195
193196 if ( stream . destroyed ) {
194197 return
195198 }
196199
197200 // Add the age header
198201 // 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
203203
204204 handler . onResponseStart ?. ( controller , statusCode , statusMessage , headers )
205205
@@ -248,9 +248,9 @@ module.exports = (opts = {}) => {
248248 }
249249 } ,
250250 new CacheRevalidationHandler (
251- ( success ) => {
251+ ( success , context ) => {
252252 if ( success ) {
253- respondWithCachedValue ( result , age )
253+ respondWithCachedValue ( result , age , context )
254254 } else if ( util . isStream ( result . body ) ) {
255255 result . body . on ( 'error' , ( ) => { } ) . destroy ( )
256256 }
@@ -264,6 +264,7 @@ module.exports = (opts = {}) => {
264264 if ( util . isStream ( opts . body ) ) {
265265 opts . body . on ( 'error' , ( ) => { } ) . destroy ( )
266266 }
267+
267268 respondWithCachedValue ( result , age )
268269 }
269270
0 commit comments