MCPcopy Create free account
hub / github.com/apache/cloudstack / createHttpBackend

Function createHttpBackend

tools/ngui/static/js/lib/angular.js:9246–9361  ·  view source on GitHub ↗
($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol)

Source from the content-addressed store, hash-verified

9244}
9245
9246function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) {
9247 // TODO(vojta): fix the signature
9248 return function(method, url, post, callback, headers, timeout, withCredentials) {
9249 $browser.$$incOutstandingRequestCount();
9250 url = url || $browser.url();
9251
9252 if (lowercase(method) == 'jsonp') {
9253 var callbackId = '_' + (callbacks.counter++).toString(36);
9254 callbacks[callbackId] = function(data) {
9255 callbacks[callbackId].data = data;
9256 };
9257
9258 jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId),
9259 function() {
9260 if (callbacks[callbackId].data) {
9261 completeRequest(callback, 200, callbacks[callbackId].data);
9262 } else {
9263 completeRequest(callback, -2);
9264 }
9265 delete callbacks[callbackId];
9266 });
9267 } else {
9268 var xhr = new XHR();
9269 xhr.open(method, url, true);
9270 forEach(headers, function(value, key) {
9271 if (value) xhr.setRequestHeader(key, value);
9272 });
9273
9274 var status;
9275
9276 // In IE6 and 7, this might be called synchronously when xhr.send below is called and the
9277 // response is in the cache. the promise api will ensure that to the app code the api is
9278 // always async
9279 xhr.onreadystatechange = function() {
9280 if (xhr.readyState == 4) {
9281 var responseHeaders = xhr.getAllResponseHeaders();
9282
9283 // TODO(vojta): remove once Firefox 21 gets released.
9284 // begin: workaround to overcome Firefox CORS http response headers bug
9285 // https://bugzilla.mozilla.org/show_bug.cgi?id=608735
9286 // Firefox already patched in nightly. Should land in Firefox 21.
9287
9288 // CORS "simple response headers" http://www.w3.org/TR/cors/
9289 var value,
9290 simpleHeaders = ["Cache-Control", "Content-Language", "Content-Type",
9291 "Expires", "Last-Modified", "Pragma"];
9292 if (!responseHeaders) {
9293 responseHeaders = "";
9294 forEach(simpleHeaders, function (header) {
9295 var value = xhr.getResponseHeader(header);
9296 if (value) {
9297 responseHeaders += header + ": " + value + "\n";
9298 }
9299 });
9300 }
9301 // end of the workaround.
9302
9303 completeRequest(callback, status || xhr.status, xhr.responseText,

Callers 1

$HttpBackendProviderFunction · 0.85

Calls 8

lowercaseFunction · 0.85
jsonpReqFunction · 0.85
completeRequestFunction · 0.85
forEachFunction · 0.85
replaceMethod · 0.80
sendMethod · 0.65
toStringMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected