Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8336b3a

Browse files
boureyjeffbcross
authored andcommitted
fix(ngResource): Remove request body from $delete
Prevent the obj.$delete instance method from sending the resource as the request body. This commit uses the existing hasBody boolean to only set httpConfig.data for methods which should have a request body. Closes #4280
1 parent 49e06ea commit 8336b3a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ angular.module('ngResource', ['ng']).
466466
}
467467
});
468468

469-
httpConfig.data = data;
469+
if (hasBody) httpConfig.data = data;
470470
route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url);
471471

472472
var promise = $http(httpConfig).then(function(response) {

test/ngResource/resourceSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ describe("resource", function() {
3232
});
3333

3434

35+
it('should not include a request body when calling $delete', function() {
36+
$httpBackend.expect('DELETE', '/fooresource', null).respond({});
37+
var Resource = $resource('/fooresource');
38+
var resource = new Resource({ foo: 'bar' });
39+
40+
resource.$delete();
41+
$httpBackend.flush();
42+
});
43+
44+
3545
it("should build resource", function() {
3646
expect(typeof CreditCard).toBe('function');
3747
expect(typeof CreditCard.get).toBe('function');

0 commit comments

Comments
 (0)