MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / createHttpBackend

Function createHttpBackend

web/static/bower_components/angular/angular.js:10639–10784  ·  view source on GitHub ↗
($browser, createXhr, $browserDefer, callbacks, rawDocument)

Source from the content-addressed store, hash-verified

10637}
10638
10639function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
10640 // TODO(vojta): fix the signature
10641 return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
10642 $browser.$$incOutstandingRequestCount();
10643 url = url || $browser.url();
10644
10645 if (lowercase(method) == 'jsonp') {
10646 var callbackId = '_' + (callbacks.counter++).toString(36);
10647 callbacks[callbackId] = function(data) {
10648 callbacks[callbackId].data = data;
10649 callbacks[callbackId].called = true;
10650 };
10651
10652 var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId),
10653 callbackId, function(status, text) {
10654 completeRequest(callback, status, callbacks[callbackId].data, "", text);
10655 callbacks[callbackId] = noop;
10656 });
10657 } else {
10658
10659 var xhr = createXhr(method, url);
10660
10661 xhr.open(method, url, true);
10662 forEach(headers, function(value, key) {
10663 if (isDefined(value)) {
10664 xhr.setRequestHeader(key, value);
10665 }
10666 });
10667
10668 xhr.onload = function requestLoaded() {
10669 var statusText = xhr.statusText || '';
10670
10671 // responseText is the old-school way of retrieving response (supported by IE9)
10672 // response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
10673 var response = ('response' in xhr) ? xhr.response : xhr.responseText;
10674
10675 // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
10676 var status = xhr.status === 1223 ? 204 : xhr.status;
10677
10678 // fix status code when it is 0 (0 status is undocumented).
10679 // Occurs when accessing file resources or on Android 4.1 stock browser
10680 // while retrieving files from application cache.
10681 if (status === 0) {
10682 status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
10683 }
10684
10685 completeRequest(callback,
10686 status,
10687 response,
10688 xhr.getAllResponseHeaders(),
10689 statusText);
10690 };
10691
10692 var requestError = function() {
10693 // The response is always empty
10694 // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
10695 completeRequest(callback, -1, null, null, '');
10696 };

Callers 1

$HttpBackendProviderFunction · 0.85

Calls 8

lowercaseFunction · 0.85
jsonpReqFunction · 0.85
completeRequestFunction · 0.85
forEachFunction · 0.85
isDefinedFunction · 0.85
urlResolveFunction · 0.85
isUndefinedFunction · 0.85
isPromiseLikeFunction · 0.85

Tested by

no test coverage detected