diff options
| author | Gonzalo Ruiz de Villa | 2013-11-13 21:24:15 +0100 | 
|---|---|---|
| committer | Igor Minar | 2013-11-21 23:09:46 -0800 | 
| commit | 6f1050df4fa885bd59ce85adbef7350ea93911a3 (patch) | |
| tree | 57b2dcbfe7575bbd659384fb777a3f23f5e3c61b /src/ng/httpBackend.js | |
| parent | 4d16472b918a3482942d76f1e273a5aa01f65e83 (diff) | |
| download | angular.js-6f1050df4fa885bd59ce85adbef7350ea93911a3.tar.bz2 | |
fix(httpBackend): should not read response data when request is aborted
When a request is aborted, it makes no sense to read the response headers or text.
Also in IE9, trying to read data (either response headers or text) from an aborted request
throws an Error c00c023f.
Fixes #4913
Closes #4940
Diffstat (limited to 'src/ng/httpBackend.js')
| -rw-r--r-- | src/ng/httpBackend.js | 14 | 
1 files changed, 11 insertions, 3 deletions
| diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index dcb15f77..5496589b 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -34,6 +34,8 @@ function $HttpBackendProvider() {  }  function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { +  var ABORTED = -1; +    // TODO(vojta): fix the signature    return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {      var status; @@ -69,13 +71,19 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,        // always async        xhr.onreadystatechange = function() {          if (xhr.readyState == 4) { -          var responseHeaders = xhr.getAllResponseHeaders(); +          var responseHeaders = null, +              response = null; + +          if(status !== ABORTED) { +            responseHeaders = xhr.getAllResponseHeaders(); +            response = xhr.responseType ? xhr.response : xhr.responseText; +          }            // responseText is the old-school way of retrieving response (supported by IE8 & 9)            // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)            completeRequest(callback,                status || xhr.status, -              (xhr.responseType ? xhr.response : xhr.responseText), +              response,                responseHeaders);          }        }; @@ -99,7 +107,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,      function timeoutRequest() { -      status = -1; +      status = ABORTED;        jsonpDone && jsonpDone();        xhr && xhr.abort();      } | 
