File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,14 @@ module.exports = class CachePolicy {
221221
222222 responseHeaders ( ) {
223223 const headers = this . _copyWithoutHopByHopHeaders ( this . _resHeaders ) ;
224- headers . age = `${ Math . round ( this . age ( ) ) } ` ;
224+ const age = this . age ( ) ;
225+
226+ // A cache SHOULD generate 113 warning if it heuristically chose a freshness
227+ // lifetime greater than 24 hours and the response's age is greater than 24 hours.
228+ if ( age > 3600 * 24 && ! this . _hasExplicitExpiration ( ) && this . maxAge ( ) > 3600 * 24 ) {
229+ headers . warning = ( headers . warning ? `${ headers . warning } , ` : '' ) + '113 - "rfc7234 5.5.4"' ;
230+ }
231+ headers . age = `${ Math . round ( age ) } ` ;
225232 return headers ;
226233 }
227234
Original file line number Diff line number Diff line change @@ -106,13 +106,28 @@ describe('Can be revalidated?', function() {
106106 const headers = cache . revalidationHeaders ( simpleRequest ) ;
107107 assertHeadersPassed ( headers ) ;
108108 assert . equal ( headers [ 'if-modified-since' ] , 'Tue, 15 Nov 1994 12:45:26 GMT' ) ;
109+ assert ( ! / 1 1 3 / . test ( headers . warning ) ) ;
109110 } ) ;
110111
111112 it ( 'not without validators' , function ( ) {
112113 const cache = new CachePolicy ( simpleRequest , cacheableResponse ) ;
113114 const headers = cache . revalidationHeaders ( simpleRequest ) ;
114115 assertHeadersPassed ( headers ) ;
115116 assertNoValidators ( headers ) ;
117+ assert ( ! / 1 1 3 / . test ( headers . warning ) ) ;
118+ } )
119+
120+ it ( '113 added' , function ( ) {
121+ const veryOldResponse = {
122+ headers : {
123+ age : 3600 * 72 ,
124+ 'last-modified' : 'Tue, 15 Nov 1994 12:45:26 GMT' ,
125+ } ,
126+ } ;
127+
128+ const cache = new CachePolicy ( simpleRequest , veryOldResponse ) ;
129+ const headers = cache . responseHeaders ( simpleRequest ) ;
130+ assert ( / 1 1 3 / . test ( headers . warning ) ) ;
116131 } )
117132
118133} ) ;
You can’t perform that action at this time.
0 commit comments