($browser, XHR, $browserDefer, callbacks, rawDocument)
| 7853 | } |
| 7854 | |
| 7855 | function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument) { |
| 7856 | var ABORTED = -1; |
| 7857 | |
| 7858 | // TODO(vojta): fix the signature |
| 7859 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { |
| 7860 | var status; |
| 7861 | $browser.$$incOutstandingRequestCount(); |
| 7862 | url = url || $browser.url(); |
| 7863 | |
| 7864 | if (lowercase(method) == 'jsonp') { |
| 7865 | var callbackId = '_' + (callbacks.counter++).toString(36); |
| 7866 | callbacks[callbackId] = function(data) { |
| 7867 | callbacks[callbackId].data = data; |
| 7868 | }; |
| 7869 | |
| 7870 | var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), |
| 7871 | function() { |
| 7872 | if (callbacks[callbackId].data) { |
| 7873 | completeRequest(callback, 200, callbacks[callbackId].data); |
| 7874 | } else { |
| 7875 | completeRequest(callback, status || -2); |
| 7876 | } |
| 7877 | delete callbacks[callbackId]; |
| 7878 | }); |
| 7879 | } else { |
| 7880 | var xhr = new XHR(); |
| 7881 | xhr.open(method, url, true); |
| 7882 | forEach(headers, function(value, key) { |
| 7883 | if (isDefined(value)) { |
| 7884 | xhr.setRequestHeader(key, value); |
| 7885 | } |
| 7886 | }); |
| 7887 | |
| 7888 | // In IE6 and 7, this might be called synchronously when xhr.send below is called and the |
| 7889 | // response is in the cache. the promise api will ensure that to the app code the api is |
| 7890 | // always async |
| 7891 | xhr.onreadystatechange = function() { |
| 7892 | if (xhr.readyState == 4) { |
| 7893 | var responseHeaders = null, |
| 7894 | response = null; |
| 7895 | |
| 7896 | if(status !== ABORTED) { |
| 7897 | responseHeaders = xhr.getAllResponseHeaders(); |
| 7898 | response = xhr.responseType ? xhr.response : xhr.responseText; |
| 7899 | } |
| 7900 | |
| 7901 | // responseText is the old-school way of retrieving response (supported by IE8 & 9) |
| 7902 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 7903 | completeRequest(callback, |
| 7904 | status || xhr.status, |
| 7905 | response, |
| 7906 | responseHeaders); |
| 7907 | } |
| 7908 | }; |
| 7909 | |
| 7910 | if (withCredentials) { |
| 7911 | xhr.withCredentials = true; |
| 7912 | } |
no test coverage detected
searching dependent graphs…