* @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)
| 9265 | </example> |
| 9266 | */ |
| 9267 | function $http(requestConfig) { |
| 9268 | var config = { |
| 9269 | method: 'get', |
| 9270 | transformRequest: defaults.transformRequest, |
| 9271 | transformResponse: defaults.transformResponse |
| 9272 | }; |
| 9273 | var headers = mergeHeaders(requestConfig); |
| 9274 | |
| 9275 | if (!angular.isObject(requestConfig)) { |
| 9276 | throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig); |
| 9277 | } |
| 9278 | |
| 9279 | extend(config, requestConfig); |
| 9280 | config.headers = headers; |
| 9281 | config.method = uppercase(config.method); |
| 9282 | |
| 9283 | var serverRequest = function(config) { |
| 9284 | headers = config.headers; |
| 9285 | var reqData = transformData(config.data, headersGetter(headers), config.transformRequest); |
| 9286 | |
| 9287 | // strip content-type if data is undefined |
| 9288 | if (isUndefined(reqData)) { |
| 9289 | forEach(headers, function(value, header) { |
| 9290 | if (lowercase(header) === 'content-type') { |
| 9291 | delete headers[header]; |
| 9292 | } |
| 9293 | }); |
| 9294 | } |
| 9295 | |
| 9296 | if (isUndefined(config.withCredentials) && !isUndefined(defaults.withCredentials)) { |
| 9297 | config.withCredentials = defaults.withCredentials; |
| 9298 | } |
| 9299 | |
| 9300 | // send request |
| 9301 | return sendReq(config, reqData, headers).then(transformResponse, transformResponse); |
| 9302 | }; |
| 9303 | |
| 9304 | var chain = [serverRequest, undefined]; |
| 9305 | var promise = $q.when(config); |
| 9306 | |
| 9307 | // apply interceptors |
| 9308 | forEach(reversedInterceptors, function(interceptor) { |
| 9309 | if (interceptor.request || interceptor.requestError) { |
| 9310 | chain.unshift(interceptor.request, interceptor.requestError); |
| 9311 | } |
| 9312 | if (interceptor.response || interceptor.responseError) { |
| 9313 | chain.push(interceptor.response, interceptor.responseError); |
| 9314 | } |
| 9315 | }); |
| 9316 | |
| 9317 | while (chain.length) { |
| 9318 | var thenFn = chain.shift(); |
| 9319 | var rejectFn = chain.shift(); |
| 9320 | |
| 9321 | promise = promise.then(thenFn, rejectFn); |
| 9322 | } |
| 9323 | |
| 9324 | promise.success = function(fn) { |
no test coverage detected