* Makes the request. * * !!! ACCESSES CLOSURE VARS: * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
(config, reqData)
| 10789 | * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests |
| 10790 | */ |
| 10791 | function sendReq(config, reqData) { |
| 10792 | var deferred = $q.defer(), |
| 10793 | promise = deferred.promise, |
| 10794 | cache, |
| 10795 | cachedResp, |
| 10796 | reqHeaders = config.headers, |
| 10797 | url = buildUrl(config.url, config.paramSerializer(config.params)); |
| 10798 | |
| 10799 | $http.pendingRequests.push(config); |
| 10800 | promise.then(removePendingReq, removePendingReq); |
| 10801 | |
| 10802 | |
| 10803 | if ((config.cache || defaults.cache) && config.cache !== false && |
| 10804 | (config.method === 'GET' || config.method === 'JSONP')) { |
| 10805 | cache = isObject(config.cache) ? config.cache |
| 10806 | : isObject(defaults.cache) ? defaults.cache |
| 10807 | : defaultCache; |
| 10808 | } |
| 10809 | |
| 10810 | if (cache) { |
| 10811 | cachedResp = cache.get(url); |
| 10812 | if (isDefined(cachedResp)) { |
| 10813 | if (isPromiseLike(cachedResp)) { |
| 10814 | // cached request has already been sent, but there is no response yet |
| 10815 | cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); |
| 10816 | } else { |
| 10817 | // serving from cache |
| 10818 | if (isArray(cachedResp)) { |
| 10819 | resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]); |
| 10820 | } else { |
| 10821 | resolvePromise(cachedResp, 200, {}, 'OK'); |
| 10822 | } |
| 10823 | } |
| 10824 | } else { |
| 10825 | // put the promise for the non-transformed response into cache as a placeholder |
| 10826 | cache.put(url, promise); |
| 10827 | } |
| 10828 | } |
| 10829 | |
| 10830 | |
| 10831 | // if we won't have the response in cache, set the xsrf headers and |
| 10832 | // send the request to the backend |
| 10833 | if (isUndefined(cachedResp)) { |
| 10834 | var xsrfValue = urlIsSameOrigin(config.url) |
| 10835 | ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName] |
| 10836 | : undefined; |
| 10837 | if (xsrfValue) { |
| 10838 | reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; |
| 10839 | } |
| 10840 | |
| 10841 | $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, |
| 10842 | config.withCredentials, config.responseType); |
| 10843 | } |
| 10844 | |
| 10845 | return promise; |
| 10846 | |
| 10847 | |
| 10848 | /** |
no test coverage detected