mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Merge pull request #828 from mzabriskie/feature/return-last-request-in-redirects
Return the last request made in axios response
This commit is contained in:
@@ -358,7 +358,12 @@ The response for a request contains the following information.
|
|||||||
headers: {},
|
headers: {},
|
||||||
|
|
||||||
// `config` is the config that was provided to `axios` for the request
|
// `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: {}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -151,12 +151,15 @@ module.exports = function httpAdapter(config) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return the last request in case of redirects
|
||||||
|
var lastRequest = res.req || req;
|
||||||
|
|
||||||
var response = {
|
var response = {
|
||||||
status: res.statusCode,
|
status: res.statusCode,
|
||||||
statusText: res.statusMessage,
|
statusText: res.statusMessage,
|
||||||
headers: res.headers,
|
headers: res.headers,
|
||||||
config: config,
|
config: config,
|
||||||
request: req
|
request: lastRequest
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.responseType === 'stream') {
|
if (config.responseType === 'stream') {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ module.exports = {
|
|||||||
}).listen(4444, function () {
|
}).listen(4444, function () {
|
||||||
axios.get('http://localhost:4444/one').then(function (res) {
|
axios.get('http://localhost:4444/one').then(function (res) {
|
||||||
test.equal(res.data, str);
|
test.equal(res.data, str);
|
||||||
|
test.equal(res.request.path, '/two');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user