fix($http): don't convert FormData objects to JSON

This won't enable FormData uploads in itself, as the Content-Type is automatically set to application/json.

Closes #10373
This commit is contained in:
Rouven Weßling
2014-12-08 23:25:45 +01:00
committed by Pawel Kozlowski
parent c437d0a470
commit 4025883803
4 changed files with 17 additions and 1 deletions

View File

@@ -51,6 +51,7 @@
"isWindow": false,
"isScope": false,
"isFile": false,
"isFormData": false,
"isBlob": false,
"isBoolean": false,
"isPromiseLike": false,

View File

@@ -45,6 +45,7 @@
isWindow: true,
isScope: true,
isFile: true,
isFormData: true,
isBlob: true,
isBoolean: true,
isPromiseLike: true,
@@ -566,6 +567,11 @@ function isFile(obj) {
}
function isFormData(obj) {
return toString.call(obj) === '[object FormData]';
}
function isBlob(obj) {
return toString.call(obj) === '[object Blob]';
}

View File

@@ -142,7 +142,7 @@ function $HttpProvider() {
// transform outgoing request data
transformRequest: [function(d) {
return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d;
return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
}],
// default headers

View File

@@ -991,6 +991,15 @@ describe('$http', function() {
$http({ method: 'POST', url: '/url', data: blob });
});
it('should ignore FormData objects', function() {
if (!window.FormData) return;
var formData = new FormData();
formData.append('angular', 'is great');
$httpBackend.expect('POST', '/url', '[object FormData]').respond('');
$http({ method: 'POST', url: '/url', data: formData });
});
it('should have access to request headers', function() {
$httpBackend.expect('POST', '/url', 'header1').respond(200);