Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Commit

Permalink
Simplify logging/ debugging for interceptor configuration
Browse files Browse the repository at this point in the history
No longer beget the config object to protect it from modification. If a
particular interceptor is concerned about late external influence, it may
return a new object during it's configuration phase.

Fixes: #61
  • Loading branch information
scothis committed Jan 11, 2015
1 parent 6fa1cac commit 0d46566
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Change Log
- installation via jspm and loader support for System.js
- support for Android 4.0-5.0 (no code changes required, now actively testing)
- support for Safari 8, iOS 8.0 and 8.1 (no code changes required, now actively testing)
- raw configuration objects are retained by interceptors, config objects are no longer begotten
- transient timeouts via config.transient on rest/interceptor/timeout, allows retry interceptor to wrap timeout
- request.mixin properties attempt setting before before and after opening the request. Some browsers (IE) are sensitive to when the properties are set.
- wire.js rest factory interceptors now wire configuration objects
Expand Down
4 changes: 2 additions & 2 deletions interceptor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors
* Copyright 2012-2015 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
Expand Down Expand Up @@ -109,7 +109,7 @@
target = handlers.client || defaultClient;
}

config = initHandler(Object.create(config || {}));
config = initHandler(config || {});

function interceptedClient(request) {
var context, meta;
Expand Down
23 changes: 9 additions & 14 deletions test/interceptor-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2015 the original author or authors
* @license MIT, see LICENSE.txt for details
*
* @author Scott Andrews
Expand Down Expand Up @@ -310,14 +310,12 @@
theInterceptor = interceptor({
request: function (request, config) {
request.phase = 'request';
refute.same(theConfig, config);
assert.same(theConfig.foo, config.foo);
assert.same(theConfig, config);
return request;
},
response: function (response, config) {
response.phase = 'response';
refute.same(theConfig, config);
assert.same(theConfig.foo, config.foo);
assert.same(theConfig, config);
return response;
}
});
Expand Down Expand Up @@ -444,32 +442,29 @@
assert.same('default', response.id);
}).otherwise(fail);
},
'should initialize the config object, without modifying the provided object': function () {
'should initialize the config object, modifying the provided object': function () {
var theConfig, theInterceptor, client;
theConfig = { foo: 'bar' };
theInterceptor = interceptor({
init: function (config) {
refute.same(theConfig, config);
assert.same('bar', config.foo);
assert.same(theConfig, config);
config.bleep = 'bloop';
return config;
},
request: function (request, config) {
refute.same(theConfig, config);
assert.same('bar', config.foo);
config.foo = 'not-bar';
assert.same('bar', theConfig.foo);
assert.same(theConfig, config);
request.phase = 'request';
return request;
},
response: function (response, config) {
assert.same('not-bar', config.foo);
assert.same('bar', theConfig.foo);
assert.same(theConfig, config);
response.phase = 'response';
return response;
}
});
refute('bleep' in theConfig);
client = theInterceptor(defaultClient, theConfig);
assert.same('bloop', theConfig.bleep);
return client().then(function (response) {
assert.same('request', response.request.phase);
assert.same('response', response.phase);
Expand Down

0 comments on commit 0d46566

Please sign in to comment.