($browser, createXhr, $browserDefer, callbacks, rawDocument)
| 9808 | } |
| 9809 | |
| 9810 | function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { |
| 9811 | // TODO(vojta): fix the signature |
| 9812 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { |
| 9813 | $browser.$$incOutstandingRequestCount(); |
| 9814 | url = url || $browser.url(); |
| 9815 | |
| 9816 | if (lowercase(method) == 'jsonp') { |
| 9817 | var callbackId = '_' + (callbacks.counter++).toString(36); |
| 9818 | callbacks[callbackId] = function(data) { |
| 9819 | callbacks[callbackId].data = data; |
| 9820 | callbacks[callbackId].called = true; |
| 9821 | }; |
| 9822 | |
| 9823 | var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), |
| 9824 | callbackId, function(status, text) { |
| 9825 | completeRequest(callback, status, callbacks[callbackId].data, "", text); |
| 9826 | callbacks[callbackId] = noop; |
| 9827 | }); |
| 9828 | } else { |
| 9829 | |
| 9830 | var xhr = createXhr(); |
| 9831 | |
| 9832 | xhr.open(method, url, true); |
| 9833 | forEach(headers, function(value, key) { |
| 9834 | if (isDefined(value)) { |
| 9835 | xhr.setRequestHeader(key, value); |
| 9836 | } |
| 9837 | }); |
| 9838 | |
| 9839 | xhr.onload = function requestLoaded() { |
| 9840 | var statusText = xhr.statusText || ''; |
| 9841 | |
| 9842 | // responseText is the old-school way of retrieving response (supported by IE9) |
| 9843 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 9844 | var response = ('response' in xhr) ? xhr.response : xhr.responseText; |
| 9845 | |
| 9846 | // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) |
| 9847 | var status = xhr.status === 1223 ? 204 : xhr.status; |
| 9848 | |
| 9849 | // fix status code when it is 0 (0 status is undocumented). |
| 9850 | // Occurs when accessing file resources or on Android 4.1 stock browser |
| 9851 | // while retrieving files from application cache. |
| 9852 | if (status === 0) { |
| 9853 | status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0; |
| 9854 | } |
| 9855 | |
| 9856 | completeRequest(callback, |
| 9857 | status, |
| 9858 | response, |
| 9859 | xhr.getAllResponseHeaders(), |
| 9860 | statusText); |
| 9861 | }; |
| 9862 | |
| 9863 | var requestError = function() { |
| 9864 | // The response is always empty |
| 9865 | // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error |
| 9866 | completeRequest(callback, -1, null, null, ''); |
| 9867 | }; |
no test coverage detected