aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ng/http.js16
-rw-r--r--test/ng/httpSpec.js16
2 files changed, 32 insertions, 0 deletions
diff --git a/src/ng/http.js b/src/ng/http.js
index 3942c5c7..0c16e2d0 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -223,6 +223,9 @@ function $HttpProvider() {
* with name equal to the lower-cased http method name, e.g.
* `$httpProvider.defaults.headers.get['My-Header']='value'`.
*
+ * Additionally, the defaults can be set at runtime via the `$http.defaults` object in a similar
+ * fassion as described above.
+ *
*
* # Transforming Requests and Responses
*
@@ -604,6 +607,19 @@ function $HttpProvider() {
*/
createShortMethodsWithData('post', 'put');
+ /**
+ * @ngdoc property
+ * @name angular.module.ng.$http#defaults
+ * @propertyOf angular.module.ng.$http
+ *
+ * @description
+ * Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of
+ * default headers as well as request and response transformations.
+ *
+ * See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above.
+ */
+ $http.defaults = $config;
+
return $http;
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();
+ });
+ });
});