MCPcopy
hub / github.com/angular-ui/ui-router / sendReq

Function sendReq

test/angular/1.2/angular.js:8405–8504  ·  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

8403 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
8404 */
8405 function sendReq(config, reqData, reqHeaders) {
8406 var deferred = $q.defer(),
8407 promise = deferred.promise,
8408 cache,
8409 cachedResp,
8410 url = buildUrl(config.url, config.params);
8411
8412 $http.pendingRequests.push(config);
8413 promise.then(removePendingReq, removePendingReq);
8414
8415
8416 if ((config.cache || defaults.cache) && config.cache !== false &&
8417 (config.method === 'GET' || config.method === 'JSONP')) {
8418 cache = isObject(config.cache) ? config.cache
8419 : isObject(defaults.cache) ? defaults.cache
8420 : defaultCache;
8421 }
8422
8423 if (cache) {
8424 cachedResp = cache.get(url);
8425 if (isDefined(cachedResp)) {
8426 if (isPromiseLike(cachedResp)) {
8427 // cached request has already been sent, but there is no response yet
8428 cachedResp.then(removePendingReq, removePendingReq);
8429 return cachedResp;
8430 } else {
8431 // serving from cache
8432 if (isArray(cachedResp)) {
8433 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]);
8434 } else {
8435 resolvePromise(cachedResp, 200, {}, 'OK');
8436 }
8437 }
8438 } else {
8439 // put the promise for the non-transformed response into cache as a placeholder
8440 cache.put(url, promise);
8441 }
8442 }
8443
8444
8445 // if we won't have the response in cache, set the xsrf headers and
8446 // send the request to the backend
8447 if (isUndefined(cachedResp)) {
8448 var xsrfValue = urlIsSameOrigin(config.url)
8449 ? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName]
8450 : undefined;
8451 if (xsrfValue) {
8452 reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
8453 }
8454
8455 $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
8456 config.withCredentials, config.responseType);
8457 }
8458
8459 return promise;
8460
8461
8462 /**

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