revert($resource): support custom headers per action

This reverts commit b936e52874.

This commit introduces a feature and should haven't been merged
into the stable branch.
This commit is contained in:
Igor Minar 2012-11-11 12:07:26 +01:00
parent f5b567d44b
commit 29541e735d
2 changed files with 4 additions and 22 deletions

View file

@ -36,8 +36,8 @@
* @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
* default set of resource actions. The declaration should be created in the following format: * default set of resource actions. The declaration should be created in the following format:
* *
* {action1: {method:?, params:?, isArray:?, headers:?}, * {action1: {method:?, params:?, isArray:?},
* action2: {method:?, params:?, isArray:?, headers:?}, * action2: {method:?, params:?, isArray:?},
* ...} * ...}
* *
* Where: * Where:
@ -49,7 +49,6 @@
* - `params` {object=} Optional set of pre-bound parameters for this action. * - `params` {object=} Optional set of pre-bound parameters for this action.
* - isArray {boolean=} If true then the returned object for this action is an array, see * - isArray {boolean=} If true then the returned object for this action is an array, see
* `returns` section. * `returns` section.
* - `headers` {object=} Optional HTTP headers to send
* *
* @returns {Object} A resource "class" object with methods for the default set of resource actions * @returns {Object} A resource "class" object with methods for the default set of resource actions
* optionally extended with custom `actions`. The default set contains these actions: * optionally extended with custom `actions`. The default set contains these actions:
@ -131,7 +130,7 @@
* The object returned from this function execution is a resource "class" which has "static" method * The object returned from this function execution is a resource "class" which has "static" method
* for each action in the definition. * for each action in the definition.
* *
* Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and `headers`. * Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
* When the data is returned from the server then the object is an instance of the resource type and * When the data is returned from the server then the object is an instance of the resource type and
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
* operations (create, read, update, delete) on server-side data. * operations (create, read, update, delete) on server-side data.
@ -370,8 +369,7 @@ angular.module('ngResource', ['ng']).
$http({ $http({
method: action.method, method: action.method,
url: route.url(extend({}, extractParams(data, action.params || {}), params)), url: route.url(extend({}, extractParams(data, action.params || {}), params)),
data: data, data: data
headers: extend({}, action.headers || {})
}).then(function(response) { }).then(function(response) {
var data = response.data; var data = response.data;

View file

@ -14,14 +14,7 @@ describe("resource", function() {
}, },
patch: { patch: {
method: 'PATCH' method: 'PATCH'
},
conditionalPut: {
method: 'PUT',
headers: {
'If-None-Match': '*'
}
} }
}); });
callback = jasmine.createSpy(); callback = jasmine.createSpy();
})); }));
@ -184,15 +177,6 @@ describe("resource", function() {
}); });
it('should send correct headers', function() {
$httpBackend.expectPUT('/CreditCard/123', undefined, function(headers) {
return headers['If-None-Match'] == "*";
}).respond({id:123});
CreditCard.conditionalPut({id: {key:123}});
});
it("should read partial resource", function() { it("should read partial resource", function() {
$httpBackend.expect('GET', '/CreditCard').respond([{id:{key:123}}]); $httpBackend.expect('GET', '/CreditCard').respond([{id:{key:123}}]);
var ccs = CreditCard.query(); var ccs = CreditCard.query();