* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 12651 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 12652 | */ |
| 12653 | function sendReq(config, reqData) { |
| 12654 | var deferred = $q.defer(), |
| 12655 | promise = deferred.promise, |
| 12656 | cache, |
| 12657 | cachedResp, |
| 12658 | reqHeaders = config.headers, |
| 12659 | isJsonp = lowercase(config.method) === 'jsonp', |
| 12660 | url = config.url; |
| 12661 | |
| 12662 | if (isJsonp) { |
| 12663 | // JSONP is a pretty sensitive operation where we're allowing a script to have full access to |
| 12664 | // our DOM and JS space. So we require that the URL satisfies SCE.RESOURCE_URL. |
| 12665 | url = $sce.getTrustedResourceUrl(url); |
| 12666 | } else if (!isString(url)) { |
| 12667 | // If it is not a string then the URL must be a $sce trusted object |
| 12668 | url = $sce.valueOf(url); |
| 12669 | } |
| 12670 | |
| 12671 | url = buildUrl(url, config.paramSerializer(config.params)); |
| 12672 | |
| 12673 | if (isJsonp) { |
| 12674 | // Check the url and add the JSONP callback placeholder |
| 12675 | url = sanitizeJsonpCallbackParam(url, config.jsonpCallbackParam); |
| 12676 | } |
| 12677 | |
| 12678 | $http.pendingRequests.push(config); |
| 12679 | promise.then(removePendingReq, removePendingReq); |
| 12680 | |
| 12681 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 12682 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 12683 | cache = isObject(config.cache) ? config.cache |
| 12684 | : isObject(/** @type {?} */ (defaults).cache) |
| 12685 | ? /** @type {?} */ (defaults).cache |
| 12686 | : defaultCache; |
| 12687 | } |
| 12688 | |
| 12689 | if (cache) { |
| 12690 | cachedResp = cache.get(url); |
| 12691 | if (isDefined(cachedResp)) { |
| 12692 | if (isPromiseLike(cachedResp)) { |
| 12693 | // cached request has already been sent, but there is no response yet |
| 12694 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 12695 | } else { |
| 12696 | // serving from cache |
| 12697 | if (isArray(cachedResp)) { |
| 12698 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3], cachedResp[4]); |
| 12699 | } else { |
| 12700 | resolvePromise(cachedResp, 200, {}, 'OK', 'complete'); |
| 12701 | } |
| 12702 | } |
| 12703 | } else { |
| 12704 | // put the promise for the non-transformed response into cache as a placeholder |
| 12705 | cache.put(url, promise); |
| 12706 | } |
| 12707 | } |
| 12708 | |
| 12709 | |
| 12710 | // if we won't have the response in cache, set the xsrf headers and |
no test coverage detected