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

Function sendReq

lib/test/angular/1.6.7/angular.js:12497–12649  ·  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

12495 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
12496 */
12497 function sendReq(config, reqData) {
12498 var deferred = $q.defer(),
12499 promise = deferred.promise,
12500 cache,
12501 cachedResp,
12502 reqHeaders = config.headers,
12503 isJsonp = lowercase(config.method) === 'jsonp',
12504 url = config.url;
12505
12506 if (isJsonp) {
12507 // JSONP is a pretty sensitive operation where we're allowing a script to have full access to
12508 // our DOM and JS space. So we require that the URL satisfies SCE.RESOURCE_URL.
12509 url = $sce.getTrustedResourceUrl(url);
12510 } else if (!isString(url)) {
12511 // If it is not a string then the URL must be a $sce trusted object
12512 url = $sce.valueOf(url);
12513 }
12514
12515 url = buildUrl(url, config.paramSerializer(config.params));
12516
12517 if (isJsonp) {
12518 // Check the url and add the JSONP callback placeholder
12519 url = sanitizeJsonpCallbackParam(url, config.jsonpCallbackParam);
12520 }
12521
12522 $http.pendingRequests.push(config);
12523 promise.then(removePendingReq, removePendingReq);
12524
12525 if ((config.cache || defaults.cache) && config.cache !== false &&
12526 (config.method === 'GET' || config.method === 'JSONP')) {
12527 cache = isObject(config.cache) ? config.cache
12528 : isObject(/** @type {?} */ (defaults).cache)
12529 ? /** @type {?} */ (defaults).cache
12530 : defaultCache;
12531 }
12532
12533 if (cache) {
12534 cachedResp = cache.get(url);
12535 if (isDefined(cachedResp)) {
12536 if (isPromiseLike(cachedResp)) {
12537 // cached request has already been sent, but there is no response yet
12538 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
12539 } else {
12540 // serving from cache
12541 if (isArray(cachedResp)) {
12542 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3], cachedResp[4]);
12543 } else {
12544 resolvePromise(cachedResp, 200, {}, 'OK', 'complete');
12545 }
12546 }
12547 } else {
12548 // put the promise for the non-transformed response into cache as a placeholder
12549 cache.put(url, promise);
12550 }
12551 }
12552
12553
12554 // if we won't have the response in cache, set the xsrf headers and

Callers 1

serverRequestFunction · 0.70

Calls 14

lowercaseFunction · 0.70
isStringFunction · 0.70
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