angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$http service is also caching the config object

Open dragosrususv opened this issue 12 years ago • 8 comments

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.

dragosrususv avatar Sep 09 '14 23:09 dragosrususv

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?

dragosrususv avatar Sep 10 '14 13:09 dragosrususv

We also have this problem in our project. Any idea if a fix could be included in one of the 1.3 release candidates?

iorzetic avatar Sep 10 '14 13:09 iorzetic

@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?

dragosrususv avatar Sep 17 '14 21:09 dragosrususv

Assigning to @jeffbcross as he is dealing with @shahata's PR

petebacondarwin avatar Sep 19 '14 20:09 petebacondarwin

rc3 is out but this is not merged - any news?

dragosrususv avatar Oct 01 '14 12:10 dragosrususv

@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 avatar Oct 14 '14 10:10 dragosrususv

@dragosrususv please tone down your comments

lgalfaso avatar Oct 14 '14 11:10 lgalfaso

@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?

dragosrususv avatar Oct 14 '14 11:10 dragosrususv