* @ngdoc service * @kind function * @name $http * @requires ng.$httpBackend * @requires $cacheFactory * @requires $rootScope * @requires $q * @requires $injector * * @description * The `$http` service is a core Angular service that facilitates commun
(requestConfig)
| 10903 | </example> |
| 10904 | */ |
| 10905 | function $http(requestConfig) { |
| 10906 | |
| 10907 | if (!isObject(requestConfig)) { |
| 10908 | throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig); |
| 10909 | } |
| 10910 | |
| 10911 | if (!isString(requestConfig.url)) { |
| 10912 | throw minErr('$http')('badreq', 'Http request configuration url must be a string. Received: {0}', requestConfig.url); |
| 10913 | } |
| 10914 | |
| 10915 | var config = extend({ |
| 10916 | method: 'get', |
| 10917 | transformRequest: defaults.transformRequest, |
| 10918 | transformResponse: defaults.transformResponse, |
| 10919 | paramSerializer: defaults.paramSerializer |
| 10920 | }, requestConfig); |
| 10921 | |
| 10922 | config.headers = mergeHeaders(requestConfig); |
| 10923 | config.method = uppercase(config.method); |
| 10924 | config.paramSerializer = isString(config.paramSerializer) ? |
| 10925 | $injector.get(config.paramSerializer) : config.paramSerializer; |
| 10926 | |
| 10927 | var serverRequest = function(config) { |
| 10928 | var headers = config.headers; |
| 10929 | var reqData = transformData(config.data, headersGetter(headers), undefined, config.transformRequest); |
| 10930 | |
| 10931 | // strip content-type if data is undefined |
| 10932 | if (isUndefined(reqData)) { |
| 10933 | forEach(headers, function(value, header) { |
| 10934 | if (lowercase(header) === 'content-type') { |
| 10935 | delete headers[header]; |
| 10936 | } |
| 10937 | }); |
| 10938 | } |
| 10939 | |
| 10940 | if (isUndefined(config.withCredentials) && !isUndefined(defaults.withCredentials)) { |
| 10941 | config.withCredentials = defaults.withCredentials; |
| 10942 | } |
| 10943 | |
| 10944 | // send request |
| 10945 | return sendReq(config, reqData).then(transformResponse, transformResponse); |
| 10946 | }; |
| 10947 | |
| 10948 | var chain = [serverRequest, undefined]; |
| 10949 | var promise = $q.when(config); |
| 10950 | |
| 10951 | // apply interceptors |
| 10952 | forEach(reversedInterceptors, function(interceptor) { |
| 10953 | if (interceptor.request || interceptor.requestError) { |
| 10954 | chain.unshift(interceptor.request, interceptor.requestError); |
| 10955 | } |
| 10956 | if (interceptor.response || interceptor.responseError) { |
| 10957 | chain.push(interceptor.response, interceptor.responseError); |
| 10958 | } |
| 10959 | }); |
| 10960 | |
| 10961 | while (chain.length) { |
| 10962 | var thenFn = chain.shift(); |
no test coverage detected