MCPcopy
hub / github.com/angular-ui/ui-router / createHttpBackend

Function createHttpBackend

test/angular/1.6/angular.js:12895–13072  ·  view source on GitHub ↗
($browser, createXhr, $browserDefer, callbacks, rawDocument)

Source from the content-addressed store, hash-verified

12893}
12894
12895function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
12896 // TODO(vojta): fix the signature
12897 return function(method, url, post, callback, headers, timeout, withCredentials, responseType, eventHandlers, uploadEventHandlers) {
12898 url = url || $browser.url();
12899
12900 if (lowercase(method) === 'jsonp') {
12901 var callbackPath = callbacks.createCallback(url);
12902 var jsonpDone = jsonpReq(url, callbackPath, function(status, text) {
12903 // jsonpReq only ever sets status to 200 (OK), 404 (ERROR) or -1 (WAITING)
12904 var response = (status === 200) && callbacks.getResponse(callbackPath);
12905 completeRequest(callback, status, response, '', text, 'complete');
12906 callbacks.removeCallback(callbackPath);
12907 });
12908 } else {
12909
12910 var xhr = createXhr(method, url);
12911 var abortedByTimeout = false;
12912
12913 xhr.open(method, url, true);
12914 forEach(headers, function(value, key) {
12915 if (isDefined(value)) {
12916 xhr.setRequestHeader(key, value);
12917 }
12918 });
12919
12920 xhr.onload = function requestLoaded() {
12921 var statusText = xhr.statusText || '';
12922
12923 // responseText is the old-school way of retrieving response (supported by IE9)
12924 // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
12925 var response = ('response' in xhr) ? xhr.response : xhr.responseText;
12926
12927 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
12928 var status = xhr.status === 1223 ? 204 : xhr.status;
12929
12930 // fix status code when it is 0 (0 status is undocumented).
12931 // Occurs when accessing file resources or on Android 4.1 stock browser
12932 // while retrieving files from application cache.
12933 if (status === 0) {
12934 status = response ? 200 : urlResolve(url).protocol === 'file' ? 404 : 0;
12935 }
12936
12937 completeRequest(callback,
12938 status,
12939 response,
12940 xhr.getAllResponseHeaders(),
12941 statusText,
12942 'complete');
12943 };
12944
12945 var requestError = function() {
12946 // The response is always empty
12947 // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
12948 completeRequest(callback, -1, null, null, '', 'error');
12949 };
12950
12951 var requestAborted = function() {
12952 completeRequest(callback, -1, null, null, '', abortedByTimeout ? 'timeout' : 'abort');

Callers 1

$HttpBackendProviderFunction · 0.70

Calls 11

urlMethod · 0.80
lowercaseFunction · 0.70
jsonpReqFunction · 0.70
completeRequestFunction · 0.70
forEachFunction · 0.70
isDefinedFunction · 0.70
urlResolveFunction · 0.70
isUndefinedFunction · 0.70
timeoutRequestFunction · 0.70
isPromiseLikeFunction · 0.70
createXhrFunction · 0.50

Tested by

no test coverage detected