Skip to content
Permalink
Browse files

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
  • Loading branch information
realityking authored and pkozlowski-opensource committed Dec 8, 2014
1 parent c437d0a commit 40258838031604feecb862afdc6f1f503d80ce4a
Showing with 17 additions and 1 deletion.
  1. +1 −0 src/.jshintrc
  2. +6 −0 src/Angular.js
  3. +1 −1 src/ng/http.js
  4. +9 −0 test/ng/httpSpec.js
@@ -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);

0 comments on commit 4025883

Please sign in to comment.
You can’t perform that action at this time.