aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ng/http.js14
-rw-r--r--test/ng/httpSpec.js9
2 files changed, 17 insertions, 6 deletions
diff --git a/src/ng/http.js b/src/ng/http.js
index a7f3b92d..708a0650 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -123,7 +123,8 @@ function isSuccess(status) {
function $HttpProvider() {
var JSON_START = /^\s*(\[|\{[^\{])/,
JSON_END = /[\}\]]\s*$/,
- PROTECTION_PREFIX = /^\)\]\}',?\n/;
+ PROTECTION_PREFIX = /^\)\]\}',?\n/,
+ CONTENT_TYPE_APPLICATION_JSON = {'Content-Type': 'application/json;charset=utf-8'};
var defaults = this.defaults = {
// transform incoming response data
@@ -147,8 +148,9 @@ function $HttpProvider() {
common: {
'Accept': 'application/json, text/plain, */*'
},
- post: {'Content-Type': 'application/json;charset=utf-8'},
- put: {'Content-Type': 'application/json;charset=utf-8'}
+ post: CONTENT_TYPE_APPLICATION_JSON,
+ put: CONTENT_TYPE_APPLICATION_JSON,
+ patch: CONTENT_TYPE_APPLICATION_JSON
},
xsrfCookieName: 'XSRF-TOKEN',
@@ -340,7 +342,7 @@ function $HttpProvider() {
*
* A custom default cache built with $cacheFactory can be provided in $http.defaults.cache.
* To skip it, set configuration property `cache` to `false`.
- *
+ *
*
* # Interceptors
*
@@ -873,8 +875,8 @@ function $HttpProvider() {
if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') {
- cache = isObject(config.cache) ? config.cache
- : isObject(defaults.cache) ? defaults.cache
+ cache = isObject(config.cache) ? config.cache
+ : isObject(defaults.cache) ? defaults.cache
: defaultCache;
}
diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js
index e6d1cf4f..5984106c 100644
--- a/test/ng/httpSpec.js
+++ b/test/ng/httpSpec.js
@@ -684,6 +684,15 @@ describe('$http', function() {
$httpBackend.flush();
});
+ it('should set default headers for PATCH request', function() {
+ $httpBackend.expect('PATCH', '/url', 'messageBody', function(headers) {
+ return headers['Accept'] == 'application/json, text/plain, */*' &&
+ headers['Content-Type'] == 'application/json;charset=utf-8';
+ }).respond('');
+
+ $http({url: '/url', method: 'PATCH', headers: {}, data: 'messageBody'});
+ $httpBackend.flush();
+ });
it('should set default headers for custom HTTP method', function() {
$httpBackend.expect('FOO', '/url', undefined, function(headers) {