Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the last request made in axios response #828

Merged
merged 3 commits into from Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -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: {}
}
```

Expand Down
5 changes: 4 additions & 1 deletion lib/adapters/http.js
Expand Up @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions test/unit/adapters/http.js
Expand Up @@ -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();
});
});
Expand Down