MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / sendReq

Function sendReq

code/songhop/www/lib/angular/angular.js:9534–9643  ·  view source on GitHub ↗

* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests

(config, reqData, reqHeaders)

Source from the content-addressed store, hash-verified

9532 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
9533 */
9534 function sendReq(config, reqData, reqHeaders) {
9535 var deferred = $q.defer(),
9536 promise = deferred.promise,
9537 cache,
9538 cachedResp,
9539 url = buildUrl(config.url, config.params);
9540
9541 $http.pendingRequests.push(config);
9542 promise.then(removePendingReq, removePendingReq);
9543
9544
9545 if ((config.cache || defaults.cache) && config.cache !== false &&
9546 (config.method === 'GET' || config.method === 'JSONP')) {
9547 cache = isObject(config.cache) ? config.cache
9548 : isObject(defaults.cache) ? defaults.cache
9549 : defaultCache;
9550 }
9551
9552 if (cache) {
9553 cachedResp = cache.get(url);
9554 if (isDefined(cachedResp)) {
9555 if (isPromiseLike(cachedResp)) {
9556 // cached request has already been sent, but there is no response yet
9557 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
9558 } else {
9559 // serving from cache
9560 if (isArray(cachedResp)) {
9561 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]);
9562 } else {
9563 resolvePromise(cachedResp, 200, {}, 'OK');
9564 }
9565 }
9566 } else {
9567 // put the promise for the non-transformed response into cache as a placeholder
9568 cache.put(url, promise);
9569 }
9570 }
9571
9572
9573 // if we won't have the response in cache, set the xsrf headers and
9574 // send the request to the backend
9575 if (isUndefined(cachedResp)) {
9576 var xsrfValue = urlIsSameOrigin(config.url)
9577 ? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName]
9578 : undefined;
9579 if (xsrfValue) {
9580 reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
9581 }
9582
9583 $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
9584 config.withCredentials, config.responseType);
9585 }
9586
9587 return promise;
9588
9589
9590 /**
9591 * Callback registered to $httpBackend():

Callers 1

serverRequestFunction · 0.70

Calls 9

getMethod · 0.80
buildUrlFunction · 0.70
isObjectFunction · 0.70
isDefinedFunction · 0.70
isPromiseLikeFunction · 0.70
resolvePromiseFunction · 0.70
shallowCopyFunction · 0.70
isUndefinedFunction · 0.70
urlIsSameOriginFunction · 0.70

Tested by

no test coverage detected