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

Add hasBody to ngResource action configuration #12181

Closed
wants to merge 10 commits into from
4 changes: 3 additions & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ function shallowClearAndCopy(src, dst) {
* - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
* `response` and `responseError`. Both `response` and `responseError` interceptors get called
* with `http response` object. See {@link ng.$http $http interceptors}.
* - **`hasBody`** - `{boolean}` - allows to specify if a request body is to be used (not
* required for POST,PUT,PATCH and can't disable body inclusion on this methods).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to change in order to reflect the new implementation.

*
* @param {Object} options Hash with custom settings that should extend the
* default `$resourceProvider` behavior. The supported options are:
Expand Down Expand Up @@ -640,7 +642,7 @@ angular.module('ngResource', ['ng']).
};

forEach(actions, function(action, name) {
var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method) || action.hasBody === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would find something like the following more intuitive:

var hasBody = action.hasBody === true || (action.hasBody !== false && /^(POST|PUT|PATCH)$/i.test(action.method));

Am I missing any reason why we shouldn't allow people to overwrite hasBody for POST, PUT, PATCH? (Not that they should.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with both versions of the statement. Should I modify the patch?

Copy link
Member

@gkalpak gkalpak Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you can think of a reason not to 😃

Copy link
Contributor Author

@kaufholdr kaufholdr Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to like twice to see the error but the correct statement would be:
var hasBody = action.hasBody === true || (action.hasBody !== true && /^(POST|PUT|PATCH)$/i.test(action.method));
right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant it the way I wrote it above. Your version is the same as:

var hasBody = action.hasBody === true || /^(POST|PUT|PATCH)$/i.test(action.method);

...which is not what we want.

var numericTimeout = action.timeout;
var cancellable = isDefined(action.cancellable) ?
action.cancellable : route.defaults.cancellable;
Expand Down