Skip to content

Commit

Permalink
RedirectHandler: pass original options to the new "redirection" reque…
Browse files Browse the repository at this point in the history
…st (closes #26)
  • Loading branch information
jiripudil committed Aug 10, 2019
1 parent 1710b0a commit 9733783
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/core/RedirectHandler.js
Expand Up @@ -23,7 +23,7 @@ export default class RedirectHandler {
);
}

this.makeRedirect(response.redirect, response.forceRedirect || options.forceRedirect);
this.makeRedirect(response.redirect, response.forceRedirect || options.forceRedirect, options);
evt.stopImmediatePropagation();
}
});
Expand All @@ -33,15 +33,15 @@ export default class RedirectHandler {
};
}

makeRedirect(url, force) {
makeRedirect(url, force, options = {}) {
// window.location.origin is not supported in IE 10
const origin = `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`;
const externalRedirect = /^https?/i.test(url) && ! new RegExp(`^${origin}`, 'i').test(url);
if (force || externalRedirect) {
this.locationAdapter.assign(url);

} else {
this.naja.makeRequest('GET', url);
this.naja.makeRequest('GET', url, null, options);
}
}
}
10 changes: 5 additions & 5 deletions tests/Naja.RedirectHandler.js
Expand Up @@ -27,7 +27,7 @@ describe('RedirectHandler', function () {

const mock = sinon.mock(redirectHandler);
mock.expects('makeRedirect')
.withExactArgs('/RedirectHandler/redirect/redirectTo', true)
.withExactArgs('/RedirectHandler/redirect/redirectTo', true, {})
.once();

naja.makeRequest('GET', '/RedirectHandler/redirect').then(() => {
Expand All @@ -44,7 +44,7 @@ describe('RedirectHandler', function () {

const mock = sinon.mock(redirectHandler);
mock.expects('makeRedirect')
.withExactArgs('/RedirectHandler/redirect/redirectTo', true)
.withExactArgs('/RedirectHandler/redirect/redirectTo', true, {forceRedirect: true})
.once();

naja.makeRequest('GET', '/RedirectHandler/forceRedirect/options', null, {forceRedirect: true}).then(() => {
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('RedirectHandler', function () {

const mock = sinon.mock(naja);
mock.expects('makeRequest')
.withExactArgs('GET', '/RedirectHandler/noForce')
.withExactArgs('GET', '/RedirectHandler/noForce', null, {})
.once();

redirectHandler.makeRedirect('/RedirectHandler/noForce', false);
Expand All @@ -174,7 +174,7 @@ describe('RedirectHandler', function () {

const mock = sinon.mock(naja);
mock.expects('makeRequest')
.withExactArgs('GET', 'http://localhost:9876/RedirectHandler/localUrl')
.withExactArgs('GET', 'http://localhost:9876/RedirectHandler/localUrl', null, {})
.once();

redirectHandler.makeRedirect('http://localhost:9876/RedirectHandler/localUrl', false);
Expand All @@ -187,7 +187,7 @@ describe('RedirectHandler', function () {

const mock = sinon.mock(redirectHandler.locationAdapter);
mock.expects('assign')
.withExactArgs('http://another-site.com/bar')
.withExactArgs('http://another-site.com/bar', null, {})
.once();

redirectHandler.makeRedirect('http://another-site.com/bar', false);
Expand Down

0 comments on commit 9733783

Please sign in to comment.