From cb65d19f3b5affc3e2c56617f997d0494f6d0de8 Mon Sep 17 00:00:00 2001 From: "hongcai.dhc" Date: Mon, 5 Jul 2021 11:29:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20redirect=20status=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/urllib.js | 13 ++++++------- test/urllib.test.js | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/urllib.js b/lib/urllib.js index 1b12df99..4d429515 100644 --- a/lib/urllib.js +++ b/lib/urllib.js @@ -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, diff --git a/test/urllib.test.js b/test/urllib.test.js index ea83703d..f6f9d960 100644 --- a/test/urllib.test.js +++ b/test/urllib.test.js @@ -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');