* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 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 |
no test coverage detected