@@ -1352,6 +1352,24 @@ describe('$http', function() {
1352
1352
} ) ) ;
1353
1353
1354
1354
1355
+ it ( 'should not share the pending cached headers object instance' , inject ( function ( $rootScope ) {
1356
+ var firstResult ;
1357
+ callback . andCallFake ( function ( result ) {
1358
+ expect ( result . headers ( ) ) . toEqual ( firstResult . headers ( ) ) ;
1359
+ expect ( result . headers ( ) ) . not . toBe ( firstResult . headers ( ) ) ;
1360
+ } ) ;
1361
+
1362
+ $httpBackend . expect ( 'GET' , '/url' ) . respond ( 200 , 'content' , { 'content-encoding' : 'gzip' , 'server' : 'Apache' } ) ;
1363
+ $http ( { method : 'GET' , url : '/url' , cache : cache } ) . then ( function ( result ) {
1364
+ firstResult = result ;
1365
+ } ) ;
1366
+ $http ( { method : 'GET' , url : '/url' , cache : cache } ) . then ( callback ) ;
1367
+ $httpBackend . flush ( ) ;
1368
+
1369
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1370
+ } ) ) ;
1371
+
1372
+
1355
1373
it ( 'should cache status code as well' , inject ( function ( $rootScope ) {
1356
1374
doFirstCacheRequest ( 'GET' , 201 ) ;
1357
1375
callback . andCallFake ( function ( r , status , h ) {
@@ -1381,6 +1399,40 @@ describe('$http', function() {
1381
1399
} ) ;
1382
1400
1383
1401
1402
+ it ( 'should preserve config object when resolving from cache' , function ( ) {
1403
+ $httpBackend . expect ( 'GET' , '/url' ) . respond ( 200 , 'content' ) ;
1404
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'bar' } } ) ;
1405
+ $httpBackend . flush ( ) ;
1406
+
1407
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'baz' } } ) . then ( callback ) ;
1408
+ $rootScope . $digest ( ) ;
1409
+
1410
+ expect ( callback . mostRecentCall . args [ 0 ] . config . headers . foo ) . toBe ( 'baz' ) ;
1411
+ } ) ;
1412
+
1413
+
1414
+ it ( 'should preserve config object when resolving from pending cache' , function ( ) {
1415
+ $httpBackend . expect ( 'GET' , '/url' ) . respond ( 200 , 'content' ) ;
1416
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'bar' } } ) ;
1417
+
1418
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'baz' } } ) . then ( callback ) ;
1419
+ $httpBackend . flush ( ) ;
1420
+
1421
+ expect ( callback . mostRecentCall . args [ 0 ] . config . headers . foo ) . toBe ( 'baz' ) ;
1422
+ } ) ;
1423
+
1424
+
1425
+ it ( 'should preserve config object when rejecting from pending cache' , function ( ) {
1426
+ $httpBackend . expect ( 'GET' , '/url' ) . respond ( 404 , 'content' ) ;
1427
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'bar' } } ) ;
1428
+
1429
+ $http ( { method : 'GET' , url : '/url' , cache : cache , headers : { foo : 'baz' } } ) . catch ( callback ) ;
1430
+ $httpBackend . flush ( ) ;
1431
+
1432
+ expect ( callback . mostRecentCall . args [ 0 ] . config . headers . foo ) . toBe ( 'baz' ) ;
1433
+ } ) ;
1434
+
1435
+
1384
1436
it ( 'should allow the cached value to be an empty string' , function ( ) {
1385
1437
cache . put ( '/abc' , '' ) ;
1386
1438
0 commit comments