@@ -56,6 +56,8 @@ function transform(data, fns, param) {
56
56
* @requires $exceptionHandler
57
57
* @requires $cacheFactory
58
58
*
59
+ * @property {Array.<XhrFuture> } pendingRequests Array of pending requests.
60
+ *
59
61
* @description
60
62
*/
61
63
function $HttpProvider ( ) {
@@ -89,28 +91,14 @@ function $HttpProvider() {
89
91
this . $get = [ '$httpBackend' , '$browser' , '$exceptionHandler' , '$cacheFactory' , '$rootScope' ,
90
92
function ( $httpBackend , $browser , $exceptionHandler , $cacheFactory , $rootScope ) {
91
93
92
- var cache = $cacheFactory ( '$http' ) ,
93
- pendingRequestsCount = 0 ;
94
+ var cache = $cacheFactory ( '$http' ) ;
94
95
95
96
// the actual service
96
97
function $http ( config ) {
97
98
return new XhrFuture ( ) . retry ( config ) ;
98
99
}
99
100
100
- /**
101
- * @workInProgress
102
- * @ngdoc method
103
- * @name angular.service.$http#pendingCount
104
- * @methodOf angular.service.$http
105
- *
106
- * @description
107
- * Return number of pending requests
108
- *
109
- * @returns {number } Number of pending requests
110
- */
111
- $http . pendingCount = function ( ) {
112
- return pendingRequestsCount ;
113
- } ;
101
+ $http . pendingRequests = [ ] ;
114
102
115
103
/**
116
104
* @ngdoc method
@@ -236,12 +224,14 @@ function $HttpProvider() {
236
224
/**
237
225
* Represents Request object, returned by $http()
238
226
*
239
- * !!! ACCESS CLOSURE VARS: $httpBackend, $browser, $config, $log, $rootScope, cache, pendingRequestsCount
227
+ * !!! ACCESS CLOSURE VARS:
228
+ * $httpBackend, $browser, $config, $log, $rootScope, cache, $http.pendingRequests
240
229
*/
241
230
function XhrFuture ( ) {
242
- var rawRequest , cfg = { } , callbacks = [ ] ,
231
+ var rawRequest , parsedHeaders ,
232
+ cfg = { } , callbacks = [ ] ,
243
233
defHeaders = $config . headers ,
244
- parsedHeaders ;
234
+ self = this ;
245
235
246
236
/**
247
237
* Callback registered to $httpBackend():
@@ -281,9 +271,11 @@ function $HttpProvider() {
281
271
response = transform ( response , cfg . transformResponse || $config . transformResponse , rawRequest ) ;
282
272
283
273
var regexp = statusToRegexp ( status ) ,
284
- pattern , callback ;
274
+ pattern , callback , idx ;
285
275
286
- pendingRequestsCount -- ;
276
+ // remove from pending requests
277
+ if ( ( idx = indexOf ( $http . pendingRequests , self ) ) !== - 1 )
278
+ $http . pendingRequests . splice ( idx , 1 ) ;
287
279
288
280
// normalize internal statuses to 0
289
281
status = Math . max ( status , 0 ) ;
@@ -372,7 +364,7 @@ function $HttpProvider() {
372
364
rawRequest = $httpBackend ( cfg . method , cfg . url , data , done , headers , cfg . timeout ) ;
373
365
}
374
366
375
- pendingRequestsCount ++ ;
367
+ $http . pendingRequests . push ( self ) ;
376
368
return this ;
377
369
} ;
378
370
@@ -423,6 +415,11 @@ function $HttpProvider() {
423
415
424
416
return this ;
425
417
} ;
418
+
419
+ /**
420
+ * Configuration object of the request
421
+ */
422
+ this . config = cfg ;
426
423
}
427
424
} ] ;
428
425
}
0 commit comments