File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,10 @@ export function transferCacheInterceptorFn(
100100 // POST requests are allowed either globally or at request level
101101 ( requestMethod === 'POST' && ! globalOptions . includePostRequests && ! requestOptions ) ||
102102 ( requestMethod !== 'POST' && ! ALLOWED_METHODS . includes ( requestMethod ) ) ||
103- requestOptions === false || //
103+ // Do not cache request that require authorization
104+ req . headers . has ( 'authorization' ) ||
105+ req . headers . has ( 'proxy-authorization' ) ||
106+ requestOptions === false ||
104107 globalOptions . filter ?.( req ) === false
105108 ) {
106109 return next ( req ) ;
Original file line number Diff line number Diff line change @@ -248,6 +248,22 @@ describe('TransferCache', () => {
248248 makeRequestAndExpectNone ( '/test-2?foo=1' , 'POST' , { transferCache : true } ) ;
249249 } ) ;
250250
251+ it ( 'should not cache request that requires authorization' , async ( ) => {
252+ makeRequestAndExpectOne ( '/test-auth' , 'foo' , {
253+ headers : { Authorization : 'Basic YWxhZGRpbjpvcGVuc2VzYW1l' } ,
254+ } ) ;
255+
256+ makeRequestAndExpectOne ( '/test-auth' , 'foo' ) ;
257+ } ) ;
258+
259+ it ( 'should not cache request that requires proxy authorization' , async ( ) => {
260+ makeRequestAndExpectOne ( '/test-auth' , 'foo' , {
261+ headers : { 'Proxy-Authorization' : 'Basic YWxhZGRpbjpvcGVuc2VzYW1l' } ,
262+ } ) ;
263+
264+ makeRequestAndExpectOne ( '/test-auth' , 'foo' ) ;
265+ } ) ;
266+
251267 describe ( 'caching with global setting' , ( ) => {
252268 beforeEach (
253269 withBody ( '<test-app-http></test-app-http>' , ( ) => {
You can’t perform that action at this time.
0 commit comments