From dceafd32ee140c8af5c7a0ca6cb808395fffeed3 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 10 Apr 2012 23:20:53 -0700 Subject: feat($http): expose the defaults config as $http.defaults Often it is impossible to set the http defaults during the config phase, because the config info is not available at this time. A good example is authentication - often the app needs to bootstrap, allow user to enter credentials and only then it gains access to session token which then should be sent to the server with every request. Without having the ability to set the defaults at runtime, the developer either has to resort to hacks, or has to set the session token header with every request made by the app. --- test/ng/httpSpec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 24ff50b4..9c01db65 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -940,6 +940,22 @@ describe('$http', function() { $httpBackend.flush(); }); }); + + + describe('defaults', function() { + + it('should expose the defaults object at runtime', function() { + expect($http.defaults).toBeDefined(); + + $http.defaults.headers.common.foo = 'bar'; + $httpBackend.expect('GET', '/url', undefined, function(headers) { + return headers['foo'] == 'bar'; + }).respond(''); + + $http.get('/url'); + $httpBackend.flush(); + }); + }); }); -- cgit v1.2.3