* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 11183 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 11184 | */ |
| 11185 | function sendReq(config, reqData) { |
| 11186 | var deferred = $q.defer(), |
| 11187 | promise = deferred.promise, |
| 11188 | cache, |
| 11189 | cachedResp, |
| 11190 | reqHeaders = config.headers, |
| 11191 | url = buildUrl(config.url, config.paramSerializer(config.params)); |
| 11192 | |
| 11193 | $http.pendingRequests.push(config); |
| 11194 | promise.then(removePendingReq, removePendingReq); |
| 11195 | |
| 11196 | |
| 11197 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 11198 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 11199 | cache = isObject(config.cache) ? config.cache |
| 11200 | : isObject(defaults.cache) ? defaults.cache |
| 11201 | : defaultCache; |
| 11202 | } |
| 11203 | |
| 11204 | if (cache) { |
| 11205 | cachedResp = cache.get(url); |
| 11206 | if (isDefined(cachedResp)) { |
| 11207 | if (isPromiseLike(cachedResp)) { |
| 11208 | // cached request has already been sent, but there is no response yet |
| 11209 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 11210 | } else { |
| 11211 | // serving from cache |
| 11212 | if (isArray(cachedResp)) { |
| 11213 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]); |
| 11214 | } else { |
| 11215 | resolvePromise(cachedResp, 200, {}, 'OK'); |
| 11216 | } |
| 11217 | } |
| 11218 | } else { |
| 11219 | // put the promise for the non-transformed response into cache as a placeholder |
| 11220 | cache.put(url, promise); |
| 11221 | } |
| 11222 | } |
| 11223 | |
| 11224 | |
| 11225 | // if we won't have the response in cache, set the xsrf headers and |
| 11226 | // send the request to the backend |
| 11227 | if (isUndefined(cachedResp)) { |
| 11228 | var xsrfValue = urlIsSameOrigin(config.url) |
| 11229 | ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName] |
| 11230 | : undefined; |
| 11231 | if (xsrfValue) { |
| 11232 | reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; |
| 11233 | } |
| 11234 | |
| 11235 | $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, |
| 11236 | config.withCredentials, config.responseType); |
| 11237 | } |
| 11238 | |
| 11239 | return promise; |
| 11240 | |
| 11241 | |
| 11242 | /** |
no test coverage detected