Skip to content

Commit

Permalink
fix: 🐛 redirect status code (#363)
Browse files Browse the repository at this point in the history
Co-authored-by: hongcai.dhc <hongcai.dhc@alibaba-inc.com>
  • Loading branch information
denghongcai and hongcai.dhc committed Jul 5, 2021
1 parent 27dc858 commit b730a6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,14 @@ function requestWithCallback(url, args, callback) {
timing.contentDownload = requestUseTime;
}

var headers = {};
if (res && res.headers) {
headers = res.headers;
}
var headers = res && res.headers || {};
var resStatusCode = res && res.statusCode || statusCode;
var resStatusMessage = res && res.statusMessage || statusMessage;

return {
status: statusCode,
statusCode: statusCode,
statusMessage: statusMessage,
status: resStatusCode,
statusCode: resStatusCode,
statusMessage: resStatusMessage,
headers: headers,
size: responseSize,
aborted: responseAborted,
Expand Down
2 changes: 2 additions & 0 deletions test/urllib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,8 @@ describe('test/urllib.test.js', function () {
});
urllib.on('response', function (info) {
if (info.req.options.path === '/302-to-200') {
assert(info.res.status === 302);
assert(info.res.statusCode === 302);
redirected = true;
}
assert(info.req.options.headers['custom-header'] === 'custom-header');
Expand Down

0 comments on commit b730a6c

Please sign in to comment.