$http service is also caching the config object #9004
Description
As per AngularJS documentation, each request (cached or not) should return the response with the "config – {Object} – The configuration object that was used to generate the request.". ( https://docs.angularjs.org/api/ng/service/$http ).
But that is not the case, as it's clearly visible on: https://github.com/angular/angular.js/blob/master/src/ng/http.js#L965
AngularJS is basically totally ignoring current request config and returns the cached one (cache miss one).
The fix for this is to replace the line above with:
cachedResp.then(function (response) {
response.config = config;
return response;
}, function (response) {
response.config = config;
return response;
}).then(removePendingReq, removePendingReq);
MORE INFO ON THE REAL USE CASE
Our app required an ajax service that would handle different cases:
- when network timeout occurs, stack the requests and trigger them when network is on
- when a session token expired, stack the requests, wait for the session token and trigger the requests again
In the above context, we were forced to add our own "currentRequests" array and we use a "requestId" number to identify the request when it comes back. The problem is that with this cache we are triggering requests 7 and 8 for instance and we get back 7 twice.
NOTE: I can create a branch and make a pull request with the above fix, if desired.