Skip to content

Commit b19c290

Browse files
committed
move config.isSafe to utils.isSafeOperation
1 parent e32335b commit b19c290

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/configuration.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
/**
2+
* Those are HTTP safe methods for which there is no need to pass any data with the request.
3+
*/
4+
var safeMethods = ['get', 'head', 'options', 'trace', 'getlist'];
5+
function isSafeOperation(operation) {
6+
return _.contains(safeMethods, operation.toLowerCase());
7+
};
8+
9+
10+
var utils = {
11+
isSafe: isSafe
12+
};
13+
114
// Configuration
215
var Configurer = {};
316
Configurer.init = function (object, config) {
417
object.configuration = config;
518

6-
/**
7-
* Those are HTTP safe methods for which there is no need to pass any data with the request.
8-
*/
9-
var safeMethods = ['get', 'head', 'options', 'trace', 'getlist'];
10-
config.isSafe = function (operation) {
11-
return _.contains(safeMethods, operation.toLowerCase());
12-
};
13-
1419
var absolutePattern = /^https?:\/\//i;
1520
config.isAbsoluteUrl = function (string) {
1621
return _.isUndefined(config.absoluteUrl) || _.isNull(config.absoluteUrl) ?
@@ -478,7 +483,7 @@ Configurer.init = function (object, config) {
478483
delete value.params;
479484
}
480485

481-
if (config.isSafe(value.method)) {
486+
if (utils.isSafeOperation(value.method)) {
482487

483488
resource[key] = function () {
484489
return $http(_.extend(value, {
@@ -507,7 +512,7 @@ Configurer.init = function (object, config) {
507512
var headers = _.defaults(callHeaders || {}, this.config.defaultHeaders);
508513

509514
if (etag) {
510-
if (!config.isSafe(operation)) {
515+
if (!utils.isSafeOperation(operation)) {
511516
headers['If-Match'] = etag;
512517
} else {
513518
headers['If-None-Match'] = etag;

src/models/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var RestangularBase = {
3434
return bindedFunction(callParams.params, callParams.headers, callParams.elem);
3535
};
3636

37-
if (this.$config.isSafe(operation)) {
37+
if (utils.isSafeOperation(operation)) {
3838
this[name] = createdFunction;
3939
} else {
4040
this[name] = function(elem, params, headers) {

src/service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ RestangularService.prototype.elemFunction = function (baseElement, operation, wh
278278
};
279279

280280
var errorCallback = function(response) {
281-
if (response.status === 304 && __this.config.isSafe(operation)) {
281+
if (response.status === 304 && utils.isSafeOperation(operation)) {
282282
__this.resolvePromise(deferred, response, __this, filledObject);
283283
} else if ( _.every(config.errorInterceptors, function(cb) { return cb(response, deferred, okCallback) !== false; }) ) {
284284
// triggered if no callback returns false
@@ -297,7 +297,7 @@ RestangularService.prototype.elemFunction = function (baseElement, operation, wh
297297
}
298298

299299
// FIXME don't use $http here
300-
if (__this.config.isSafe(operation)) {
300+
if (utils.isSafeOperation(operation)) {
301301
if (isOverrideOperation) {
302302
this.urlHandler.resource(baseElement, $http, request.httpConfig, callHeaders, request.params,
303303
what, etag, callOperation)[callOperation]({}).then(okCallback, errorCallback);

0 commit comments

Comments
 (0)