Skip to content

Commit b730a6c

Browse files
denghongcaihongcai.dhc
and
hongcai.dhc
authored
fix: 🐛 redirect status code (#363)
Co-authored-by: hongcai.dhc <[email protected]>
1 parent 27dc858 commit b730a6c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/urllib.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,14 @@ function requestWithCallback(url, args, callback) {
602602
timing.contentDownload = requestUseTime;
603603
}
604604

605-
var headers = {};
606-
if (res && res.headers) {
607-
headers = res.headers;
608-
}
605+
var headers = res && res.headers || {};
606+
var resStatusCode = res && res.statusCode || statusCode;
607+
var resStatusMessage = res && res.statusMessage || statusMessage;
609608

610609
return {
611-
status: statusCode,
612-
statusCode: statusCode,
613-
statusMessage: statusMessage,
610+
status: resStatusCode,
611+
statusCode: resStatusCode,
612+
statusMessage: resStatusMessage,
614613
headers: headers,
615614
size: responseSize,
616615
aborted: responseAborted,

test/urllib.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,8 @@ describe('test/urllib.test.js', function () {
17151715
});
17161716
urllib.on('response', function (info) {
17171717
if (info.req.options.path === '/302-to-200') {
1718+
assert(info.res.status === 302);
1719+
assert(info.res.statusCode === 302);
17181720
redirected = true;
17191721
}
17201722
assert(info.req.options.headers['custom-header'] === 'custom-header');

0 commit comments

Comments
 (0)