* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 11484 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 11485 | */ |
| 11486 | function sendReq(config, reqData) { |
| 11487 | var deferred = $q.defer(), |
| 11488 | promise = deferred.promise, |
| 11489 | cache, |
| 11490 | cachedResp, |
| 11491 | reqHeaders = config.headers, |
| 11492 | url = buildUrl(config.url, config.paramSerializer(config.params)); |
| 11493 | |
| 11494 | $http.pendingRequests.push(config); |
| 11495 | promise.then(removePendingReq, removePendingReq); |
| 11496 | |
| 11497 | if ((config.cache || defaults.cache) && |
| 11498 | config.cache !== false && |
| 11499 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 11500 | cache = isObject(config.cache) |
| 11501 | ? config.cache |
| 11502 | : isObject(defaults.cache) |
| 11503 | ? defaults.cache |
| 11504 | : defaultCache; |
| 11505 | } |
| 11506 | |
| 11507 | if (cache) { |
| 11508 | cachedResp = cache.get(url); |
| 11509 | if (isDefined(cachedResp)) { |
| 11510 | if (isPromiseLike(cachedResp)) { |
| 11511 | // cached request has already been sent, but there is no response yet |
| 11512 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 11513 | } else { |
| 11514 | // serving from cache |
| 11515 | if (isArray(cachedResp)) { |
| 11516 | resolvePromise(cachedResp[1], |
| 11517 | cachedResp[0], |
| 11518 | shallowCopy(cachedResp[2]), |
| 11519 | cachedResp[3]); |
| 11520 | } else { |
| 11521 | resolvePromise(cachedResp, 200, {}, 'OK'); |
| 11522 | } |
| 11523 | } |
| 11524 | } else { |
| 11525 | // put the promise for the non-transformed response into cache as a placeholder |
| 11526 | cache.put(url, promise); |
| 11527 | } |
| 11528 | } |
| 11529 | |
| 11530 | // if we won't have the response in cache, set the xsrf headers and |
| 11531 | // send the request to the backend |
| 11532 | if (isUndefined(cachedResp)) { |
| 11533 | var xsrfValue = urlIsSameOrigin(config.url) |
| 11534 | ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName] |
| 11535 | : undefined; |
| 11536 | if (xsrfValue) { |
| 11537 | reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; |
| 11538 | } |
| 11539 | |
| 11540 | $httpBackend(config.method, |
| 11541 | url, |
| 11542 | reqData, |
| 11543 | done, |
no test coverage detected