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

Function sendReq

lib/test/angular/1.8.0/angular.js:13289–13441  ·  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

13287 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
13288 */
13289 function sendReq(config, reqData) {
13290 var deferred = $q.defer(),
13291 promise = deferred.promise,
13292 cache,
13293 cachedResp,
13294 reqHeaders = config.headers,
13295 isJsonp = lowercase(config.method) === 'jsonp',
13296 url = config.url;
13297
13298 if (isJsonp) {
13299 // JSONP is a pretty sensitive operation where we're allowing a script to have full access to
13300 // our DOM and JS space. So we require that the URL satisfies SCE.RESOURCE_URL.
13301 url = $sce.getTrustedResourceUrl(url);
13302 } else if (!isString(url)) {
13303 // If it is not a string then the URL must be a $sce trusted object
13304 url = $sce.valueOf(url);
13305 }
13306
13307 url = buildUrl(url, config.paramSerializer(config.params));
13308
13309 if (isJsonp) {
13310 // Check the url and add the JSONP callback placeholder
13311 url = sanitizeJsonpCallbackParam(url, config.jsonpCallbackParam);
13312 }
13313
13314 $http.pendingRequests.push(config);
13315 promise.then(removePendingReq, removePendingReq);
13316
13317 if ((config.cache || defaults.cache) && config.cache !== false &&
13318 (config.method === 'GET' || config.method === 'JSONP')) {
13319 cache = isObject(config.cache) ? config.cache
13320 : isObject(/** @type {?} */ (defaults).cache)
13321 ? /** @type {?} */ (defaults).cache
13322 : defaultCache;
13323 }
13324
13325 if (cache) {
13326 cachedResp = cache.get(url);
13327 if (isDefined(cachedResp)) {
13328 if (isPromiseLike(cachedResp)) {
13329 // cached request has already been sent, but there is no response yet
13330 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
13331 } else {
13332 // serving from cache
13333 if (isArray(cachedResp)) {
13334 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3], cachedResp[4]);
13335 } else {
13336 resolvePromise(cachedResp, 200, {}, 'OK', 'complete');
13337 }
13338 }
13339 } else {
13340 // put the promise for the non-transformed response into cache as a placeholder
13341 cache.put(url, promise);
13342 }
13343 }
13344
13345
13346 // if we won't have the response in cache, set the xsrf headers and

Callers 1

serverRequestFunction · 0.70

Calls 13

lowercaseFunction · 0.70
isStringFunction · 0.70
buildUrlFunction · 0.70
isObjectFunction · 0.70
isDefinedFunction · 0.70
isPromiseLikeFunction · 0.70
isArrayFunction · 0.70
resolvePromiseFunction · 0.70
shallowCopyFunction · 0.70
isUndefinedFunction · 0.70
$httpBackendFunction · 0.70

Tested by

no test coverage detected