* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 10463 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 10464 | */ |
| 10465 | function sendReq(config, reqData) { |
| 10466 | var deferred = $q.defer(), |
| 10467 | promise = deferred.promise, |
| 10468 | cache, |
| 10469 | cachedResp, |
| 10470 | reqHeaders = config.headers, |
| 10471 | url = buildUrl(config.url, config.paramSerializer(config.params)); |
| 10472 | |
| 10473 | $http.pendingRequests.push(config); |
| 10474 | promise.then(removePendingReq, removePendingReq); |
| 10475 | |
| 10476 | |
| 10477 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 10478 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 10479 | cache = isObject(config.cache) ? config.cache |
| 10480 | : isObject(defaults.cache) ? defaults.cache |
| 10481 | : defaultCache; |
| 10482 | } |
| 10483 | |
| 10484 | if (cache) { |
| 10485 | cachedResp = cache.get(url); |
| 10486 | if (isDefined(cachedResp)) { |
| 10487 | if (isPromiseLike(cachedResp)) { |
| 10488 | // cached request has already been sent, but there is no response yet |
| 10489 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 10490 | } else { |
| 10491 | // serving from cache |
| 10492 | if (isArray(cachedResp)) { |
| 10493 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]); |
| 10494 | } else { |
| 10495 | resolvePromise(cachedResp, 200, {}, 'OK'); |
| 10496 | } |
| 10497 | } |
| 10498 | } else { |
| 10499 | // put the promise for the non-transformed response into cache as a placeholder |
| 10500 | cache.put(url, promise); |
| 10501 | } |
| 10502 | } |
| 10503 | |
| 10504 | |
| 10505 | // if we won't have the response in cache, set the xsrf headers and |
| 10506 | // send the request to the backend |
| 10507 | if (isUndefined(cachedResp)) { |
| 10508 | var xsrfValue = urlIsSameOrigin(config.url) |
| 10509 | ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName] |
| 10510 | : undefined; |
| 10511 | if (xsrfValue) { |
| 10512 | reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; |
| 10513 | } |
| 10514 | |
| 10515 | $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, |
| 10516 | config.withCredentials, config.responseType); |
| 10517 | } |
| 10518 | |
| 10519 | return promise; |
| 10520 | |
| 10521 | |
| 10522 | /** |
no test coverage detected