MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / createHttpBackend

Function createHttpBackend

lib/test/angular/1.7.0/angular.js:12897–13074  ·  view source on GitHub ↗
($browser, createXhr, $browserDefer, callbacks, rawDocument)

Source from the content-addressed store, hash-verified

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

Callers 1

$HttpBackendProviderFunction · 0.70

Calls 10

createXhrFunction · 0.85
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

Tested by

no test coverage detected