MCPcopy Index your code
hub / github.com/angular-ui/ui-router / sendReq

Function sendReq

test/angular/1.3/angular.js:9644–9754  ·  view source on GitHub ↗

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

(config, reqData)

Source from the content-addressed store, hash-verified

9642 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
9643 */
9644 function sendReq(config, reqData) {
9645 var deferred = $q.defer(),
9646 promise = deferred.promise,
9647 cache,
9648 cachedResp,
9649 reqHeaders = config.headers,
9650 url = buildUrl(config.url, config.params);
9651
9652 $http.pendingRequests.push(config);
9653 promise.then(removePendingReq, removePendingReq);
9654
9655
9656 if ((config.cache || defaults.cache) && config.cache !== false &&
9657 (config.method === 'GET' || config.method === 'JSONP')) {
9658 cache = isObject(config.cache) ? config.cache
9659 : isObject(defaults.cache) ? defaults.cache
9660 : defaultCache;
9661 }
9662
9663 if (cache) {
9664 cachedResp = cache.get(url);
9665 if (isDefined(cachedResp)) {
9666 if (isPromiseLike(cachedResp)) {
9667 // cached request has already been sent, but there is no response yet
9668 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
9669 } else {
9670 // serving from cache
9671 if (isArray(cachedResp)) {
9672 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]);
9673 } else {
9674 resolvePromise(cachedResp, 200, {}, 'OK');
9675 }
9676 }
9677 } else {
9678 // put the promise for the non-transformed response into cache as a placeholder
9679 cache.put(url, promise);
9680 }
9681 }
9682
9683
9684 // if we won't have the response in cache, set the xsrf headers and
9685 // send the request to the backend
9686 if (isUndefined(cachedResp)) {
9687 var xsrfValue = urlIsSameOrigin(config.url)
9688 ? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName]
9689 : undefined;
9690 if (xsrfValue) {
9691 reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
9692 }
9693
9694 $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
9695 config.withCredentials, config.responseType);
9696 }
9697
9698 return promise;
9699
9700
9701 /**

Callers 1

serverRequestFunction · 0.70

Calls 10

isArrayFunction · 0.85
buildUrlFunction · 0.70
isObjectFunction · 0.70
isDefinedFunction · 0.70
isPromiseLikeFunction · 0.70
resolvePromiseFunction · 0.70
shallowCopyFunction · 0.70
isUndefinedFunction · 0.70
urlIsSameOriginFunction · 0.70
$httpBackendFunction · 0.70

Tested by

no test coverage detected