diff --git a/README.md b/README.md index 3bc66e9ec7..a7bf758fc2 100644 --- a/README.md +++ b/README.md @@ -358,7 +358,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: {} } ``` diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 23c599baaa..10ad580c64 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -151,12 +151,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') { diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 829e2887d6..ba0ecf9c76 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(); }); });