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');