From e5beab045c6bb7092ee264a6d7cabbb9936e05b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Sat, 8 Apr 2017 12:44:41 +0200 Subject: [PATCH 1/3] Adding test checking the request in axios response is the last in a redirect --- test/unit/adapters/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 131bce0032..00416aa408 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -83,6 +83,7 @@ module.exports = { }).listen(4444, function () { axios.get('http://localhost:4444/one').then(function (res) { test.equal(res.data, str); + test.equal(res.request.path, '/two'); test.done(); }); }); From 84d9a41850fd194193a9d37eac6e0ee84d5d9f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Sat, 8 Apr 2017 12:47:20 +0200 Subject: [PATCH 2/3] Adding code to assign the last request to axios response --- lib/adapters/http.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8a2fc57dac..dc02b3bc90 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -149,12 +149,15 @@ module.exports = function httpAdapter(config) { break; } + // return the last request in case of redirects + var lastRequest = res.req || req; + var response = { status: res.statusCode, statusText: res.statusMessage, headers: res.headers, config: config, - request: req + request: lastRequest }; if (config.responseType === 'stream') { From 88cc84c91e614dfe15528c9fc4c71596a1710697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Sat, 8 Apr 2017 12:57:48 +0200 Subject: [PATCH 3/3] Adding documentation for response.request --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38cbb22550..612e4a9449 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,12 @@ The response for a request contains the following information. headers: {}, // `config` is the config that was provided to `axios` for the request - config: {} + config: {}, + + // `request` is the request that generated this response + // It is the last ClientRequest instance in node.js (in redirects) + // and an XMLHttpRequest instance the browser + request: {} } ```