@@ -2208,6 +2208,56 @@ describe('Cache Interceptor', () => {
22082208 }
22092209 } )
22102210
2211+ test ( 'does not cache response when request has Authorization and qualified no-cache/private names Authorization with OWS' , async ( ) => {
2212+ for ( const cacheControl of [
2213+ 'public, max-age=60, private=" authorization"' ,
2214+ 'public, max-age=60, no-cache="\tauthorization"' ,
2215+ 'public, max-age=60, no-cache=authorization\t'
2216+ ] ) {
2217+ let requestsToOrigin = 0
2218+ const server = createServer ( { joinDuplicateHeaders : true } , ( _ , res ) => {
2219+ requestsToOrigin ++
2220+ res . setHeader ( 'cache-control' , cacheControl )
2221+ res . end ( `authenticated ${ requestsToOrigin } ` )
2222+ } ) . listen ( 0 )
2223+
2224+ await once ( server , 'listening' )
2225+
2226+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
2227+ . compose ( interceptors . cache ( ) )
2228+
2229+ try {
2230+ const request = {
2231+ origin : 'localhost' ,
2232+ method : 'GET' ,
2233+ path : '/' ,
2234+ headers : {
2235+ authorization : 'Bearer token123'
2236+ }
2237+ }
2238+
2239+ {
2240+ const res = await client . request ( request )
2241+ equal ( requestsToOrigin , 1 )
2242+ strictEqual ( await res . body . text ( ) , 'authenticated 1' )
2243+ }
2244+
2245+ {
2246+ const res = await client . request ( {
2247+ origin : 'localhost' ,
2248+ method : 'GET' ,
2249+ path : '/'
2250+ } )
2251+ equal ( requestsToOrigin , 2 )
2252+ strictEqual ( await res . body . text ( ) , 'authenticated 2' )
2253+ }
2254+ } finally {
2255+ await client . close ( )
2256+ await new Promise ( resolve => server . close ( resolve ) )
2257+ }
2258+ }
2259+ } )
2260+
22112261 test ( 'does not cache response when request has Authorization and response only has max-age' , async ( ) => {
22122262 let requestsToOrigin = 0
22132263 const server = createServer ( { joinDuplicateHeaders : true } , ( _ , res ) => {
0 commit comments