From 721fae6c331bbd7b8f74b4763953a7ec1dd38d95 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Sun, 23 Oct 2016 10:07:56 +0200 Subject: [PATCH] Rename redirectUrl into responseUrl. The name redirectUrl didn't make sense for those cases where the request was not actually redirected. --- index.js | 2 +- test/test-with-server.js | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 7cef81e..976a832 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,7 @@ RedirectableRequest.prototype._processResponse = function (response) { this._performRequest(); } else { // The response is not a redirect; return it as-is - response.redirectUrl = this._currentUrl; + response.responseUrl = this._currentUrl; return this.emit('response', response); } }; diff --git a/test/test-with-server.js b/test/test-with-server.js index 9e7e408..4362293 100644 --- a/test/test-with-server.js +++ b/test/test-with-server.js @@ -59,7 +59,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {a: 'b'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/f'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/f'); }) .nodeify(done); }); @@ -80,7 +80,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {a: 'b'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/f'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/f'); }) .nodeify(done); }); @@ -96,7 +96,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.equal(res.statusCode, 307); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/a'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/a'); res.on('data', function () { // noop to consume the stream (server won't shut down otherwise). }); @@ -130,7 +130,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {baz: 'quz'}); - assert.deepEqual(res.redirectUrl, 'https://localhost:3601/c'); + assert.deepEqual(res.responseUrl, 'https://localhost:3601/c'); }) .nodeify(done); }); @@ -147,7 +147,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {greeting: 'hello'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/b?greeting=hello'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/b?greeting=hello'); }) .nodeify(done); }); @@ -247,7 +247,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {foo: 'bar'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/r0'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/r0'); }) // 22 redirects should fail .then(asPromise(function (resolve, reject) { @@ -267,7 +267,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {foo: 'bar'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/r0'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/r0'); }) .nodeify(done); }); @@ -314,7 +314,7 @@ describe('follow-redirects ', function () { http.request(opts, resolve).on('error', reject).end(); })) .then(function (res) { - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/b'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/b'); if (res.statusCode !== 200) { throw new Error('Did not use ' + expectedMethod); } @@ -344,7 +344,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {yes: 'no'}); - assert.deepEqual(res.redirectUrl, 'https://localhost:3601/c'); + assert.deepEqual(res.responseUrl, 'https://localhost:3601/c'); }) .nodeify(done); }); @@ -362,7 +362,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.parsedJson, {hello: 'goodbye'}); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/c'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/c'); }) .nodeify(done); }); @@ -410,7 +410,7 @@ describe('follow-redirects ', function () { })) .then(function (res) { assert.deepEqual(res.statusCode, 302); - assert.deepEqual(res.redirectUrl, 'http://localhost:3600/a'); + assert.deepEqual(res.responseUrl, 'http://localhost:3600/a'); }) .nodeify(done); });