($browser, createXhr, $browserDefer, callbacks, rawDocument)
| 9697 | } |
| 9698 | |
| 9699 | function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { |
| 9700 | // TODO(vojta): fix the signature |
| 9701 | return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { |
| 9702 | $browser.$$incOutstandingRequestCount(); |
| 9703 | url = url || $browser.url(); |
| 9704 | |
| 9705 | if (lowercase(method) == 'jsonp') { |
| 9706 | var callbackId = '_' + (callbacks.counter++).toString(36); |
| 9707 | callbacks[callbackId] = function(data) { |
| 9708 | callbacks[callbackId].data = data; |
| 9709 | callbacks[callbackId].called = true; |
| 9710 | }; |
| 9711 | |
| 9712 | var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), |
| 9713 | callbackId, function(status, text) { |
| 9714 | completeRequest(callback, status, callbacks[callbackId].data, "", text); |
| 9715 | callbacks[callbackId] = noop; |
| 9716 | }); |
| 9717 | } else { |
| 9718 | |
| 9719 | var xhr = createXhr(); |
| 9720 | |
| 9721 | xhr.open(method, url, true); |
| 9722 | forEach(headers, function(value, key) { |
| 9723 | if (isDefined(value)) { |
| 9724 | xhr.setRequestHeader(key, value); |
| 9725 | } |
| 9726 | }); |
| 9727 | |
| 9728 | xhr.onload = function requestLoaded() { |
| 9729 | var statusText = xhr.statusText || ''; |
| 9730 | |
| 9731 | // responseText is the old-school way of retrieving response (supported by IE8 & 9) |
| 9732 | // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) |
| 9733 | var response = ('response' in xhr) ? xhr.response : xhr.responseText; |
| 9734 | |
| 9735 | // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) |
| 9736 | var status = xhr.status === 1223 ? 204 : xhr.status; |
| 9737 | |
| 9738 | // fix status code when it is 0 (0 status is undocumented). |
| 9739 | // Occurs when accessing file resources or on Android 4.1 stock browser |
| 9740 | // while retrieving files from application cache. |
| 9741 | if (status === 0) { |
| 9742 | status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0; |
| 9743 | } |
| 9744 | |
| 9745 | completeRequest(callback, |
| 9746 | status, |
| 9747 | response, |
| 9748 | xhr.getAllResponseHeaders(), |
| 9749 | statusText); |
| 9750 | }; |
| 9751 | |
| 9752 | var requestError = function() { |
| 9753 | // The response is always empty |
| 9754 | // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error |
| 9755 | completeRequest(callback, -1, null, null, ''); |
| 9756 | }; |
no test coverage detected