* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 11975 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 11976 | */ |
| 11977 | function sendReq(config, reqData) { |
| 11978 | var deferred = $q.defer(), |
| 11979 | promise = deferred.promise, |
| 11980 | cache, |
| 11981 | cachedResp, |
| 11982 | reqHeaders = config.headers, |
| 11983 | url = buildUrl(config.url, config.paramSerializer(config.params)); |
| 11984 | |
| 11985 | $http.pendingRequests.push(config); |
| 11986 | promise.then(removePendingReq, removePendingReq); |
| 11987 | |
| 11988 | |
| 11989 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 11990 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 11991 | cache = isObject(config.cache) ? config.cache |
| 11992 | : isObject(defaults.cache) ? defaults.cache |
| 11993 | : defaultCache; |
| 11994 | } |
| 11995 | |
| 11996 | if (cache) { |
| 11997 | cachedResp = cache.get(url); |
| 11998 | if (isDefined(cachedResp)) { |
| 11999 | if (isPromiseLike(cachedResp)) { |
| 12000 | // cached request has already been sent, but there is no response yet |
| 12001 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 12002 | } else { |
| 12003 | // serving from cache |
| 12004 | if (isArray(cachedResp)) { |
| 12005 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]); |
| 12006 | } else { |
| 12007 | resolvePromise(cachedResp, 200, {}, 'OK'); |
| 12008 | } |
| 12009 | } |
| 12010 | } else { |
| 12011 | // put the promise for the non-transformed response into cache as a placeholder |
| 12012 | cache.put(url, promise); |
| 12013 | } |
| 12014 | } |
| 12015 | |
| 12016 | |
| 12017 | // if we won't have the response in cache, set the xsrf headers and |
| 12018 | // send the request to the backend |
| 12019 | if (isUndefined(cachedResp)) { |
| 12020 | var xsrfValue = urlIsSameOrigin(config.url) |
| 12021 | ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName] |
| 12022 | : undefined; |
| 12023 | if (xsrfValue) { |
| 12024 | reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; |
| 12025 | } |
| 12026 | |
| 12027 | $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, |
| 12028 | config.withCredentials, config.responseType, |
| 12029 | createApplyHandlers(config.eventHandlers), |
| 12030 | createApplyHandlers(config.uploadEventHandlers)); |
| 12031 | } |
| 12032 | |
| 12033 | return promise; |
| 12034 |
no test coverage detected