$http service is also caching the config object
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.
UPDATE: Found out a cleaner solution instead of the 1-line replace solution above. Can anyone please confirm that I could create a pull request for this? Does this seems reasonable?
We also have this problem in our project. Any idea if a fix could be included in one of the 1.3 release candidates?
@pkozlowski-opensource : do you think it would be reasonable to integrate @shahata's PR in one of the 1.3 release candidates? Shall we wait or just manually apply a patch for our product for the weeks to come?
Assigning to @jeffbcross as he is dealing with @shahata's PR
rc3 is out but this is not merged - any news?
@petebacondarwin / @jeffbcross : the PR for this issue is still opened and 1.3.0 was released - we are forced to go in production with an updated version of AngularJS (manually patched it). Is there any way we could consider integrating this soon?
Very disappointed of the lack of interest on your side. As community we can only raise bugs and fixed them ourselves, but not having the pro-active attitude towards such an approach, that I cannot understand.
@dragosrususv please tone down your comments
@lgalfaso : please mind this issue was labeled with 1.3.0-rc3 and someone forgot to add it. allow me to say that professionally speaking, this is not ok - in business this may cause you lots of trouble (as employer or employee). do you agree?