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

Function sendReq

lib/test/angular/1.4.3/angular.js:10283–10393  ·  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

10281 * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
10282 */
10283 function sendReq(config, reqData) {
10284 var deferred = $q.defer(),
10285 promise = deferred.promise,
10286 cache,
10287 cachedResp,
10288 reqHeaders = config.headers,
10289 url = buildUrl(config.url, config.paramSerializer(config.params));
10290
10291 $http.pendingRequests.push(config);
10292 promise.then(removePendingReq, removePendingReq);
10293
10294
10295 if ((config.cache || defaults.cache) && config.cache !== false &&
10296 (config.method === 'GET' || config.method === 'JSONP')) {
10297 cache = isObject(config.cache) ? config.cache
10298 : isObject(defaults.cache) ? defaults.cache
10299 : defaultCache;
10300 }
10301
10302 if (cache) {
10303 cachedResp = cache.get(url);
10304 if (isDefined(cachedResp)) {
10305 if (isPromiseLike(cachedResp)) {
10306 // cached request has already been sent, but there is no response yet
10307 cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult);
10308 } else {
10309 // serving from cache
10310 if (isArray(cachedResp)) {
10311 resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]);
10312 } else {
10313 resolvePromise(cachedResp, 200, {}, 'OK');
10314 }
10315 }
10316 } else {
10317 // put the promise for the non-transformed response into cache as a placeholder
10318 cache.put(url, promise);
10319 }
10320 }
10321
10322
10323 // if we won't have the response in cache, set the xsrf headers and
10324 // send the request to the backend
10325 if (isUndefined(cachedResp)) {
10326 var xsrfValue = urlIsSameOrigin(config.url)
10327 ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName]
10328 : undefined;
10329 if (xsrfValue) {
10330 reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
10331 }
10332
10333 $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
10334 config.withCredentials, config.responseType);
10335 }
10336
10337 return promise;
10338
10339
10340 /**

Callers 1

serverRequestFunction · 0.70

Calls 10

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
isArrayFunction · 0.50

Tested by

no test coverage detected