* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 13222 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 13223 | */ |
| 13224 | function sendReq(config, reqData) { |
| 13225 | var deferred = $q.defer(), |
| 13226 | promise = deferred.promise, |
| 13227 | cache, |
| 13228 | cachedResp, |
| 13229 | reqHeaders = config.headers, |
| 13230 | isJsonp = lowercase(config.method) === 'jsonp', |
| 13231 | url = config.url; |
| 13232 | |
| 13233 | if (isJsonp) { |
| 13234 | // JSONP is a pretty sensitive operation where we're allowing a script to have full access to |
| 13235 | // our DOM and JS space. So we require that the URL satisfies SCE.RESOURCE_URL. |
| 13236 | url = $sce.getTrustedResourceUrl(url); |
| 13237 | } else if (!isString(url)) { |
| 13238 | // If it is not a string then the URL must be a $sce trusted object |
| 13239 | url = $sce.valueOf(url); |
| 13240 | } |
| 13241 | |
| 13242 | url = buildUrl(url, config.paramSerializer(config.params)); |
| 13243 | |
| 13244 | if (isJsonp) { |
| 13245 | // Check the url and add the JSONP callback placeholder |
| 13246 | url = sanitizeJsonpCallbackParam(url, config.jsonpCallbackParam); |
| 13247 | } |
| 13248 | |
| 13249 | $http.pendingRequests.push(config); |
| 13250 | promise.then(removePendingReq, removePendingReq); |
| 13251 | |
| 13252 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 13253 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 13254 | cache = isObject(config.cache) ? config.cache |
| 13255 | : isObject(/** @type {?} */ (defaults).cache) |
| 13256 | ? /** @type {?} */ (defaults).cache |
| 13257 | : defaultCache; |
| 13258 | } |
| 13259 | |
| 13260 | if (cache) { |
| 13261 | cachedResp = cache.get(url); |
| 13262 | if (isDefined(cachedResp)) { |
| 13263 | if (isPromiseLike(cachedResp)) { |
| 13264 | // cached request has already been sent, but there is no response yet |
| 13265 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 13266 | } else { |
| 13267 | // serving from cache |
| 13268 | if (isArray(cachedResp)) { |
| 13269 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3], cachedResp[4]); |
| 13270 | } else { |
| 13271 | resolvePromise(cachedResp, 200, {}, 'OK', 'complete'); |
| 13272 | } |
| 13273 | } |
| 13274 | } else { |
| 13275 | // put the promise for the non-transformed response into cache as a placeholder |
| 13276 | cache.put(url, promise); |
| 13277 | } |
| 13278 | } |
| 13279 | |
| 13280 | |
| 13281 | // if we won't have the response in cache, set the xsrf headers and |
no test coverage detected