mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-19 17:53:27 +08:00
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:
committed by
Pawel Kozlowski
parent
c437d0a470
commit
4025883803
@@ -51,6 +51,7 @@
|
||||
"isWindow": false,
|
||||
"isScope": false,
|
||||
"isFile": false,
|
||||
"isFormData": false,
|
||||
"isBlob": false,
|
||||
"isBoolean": false,
|
||||
"isPromiseLike": false,
|
||||
|
||||
@@ -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]';
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user