From cfafc1572f3f0f04fdbdf542513a352677b73078 Mon Sep 17 00:00:00 2001 From: Kinka Huang Date: Fri, 13 Oct 2023 19:03:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20getAllResponseHeaders=20=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E8=BF=94=E5=9B=9Enull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/request.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/request.js b/lib/request.js index c2dd03e..ca248b1 100644 --- a/lib/request.js +++ b/lib/request.js @@ -37,14 +37,17 @@ var queryStringify = function(obj, sep, eq, name) { var xhrRes = function (err, xhr, body) { var headers = {}; - xhr.getAllResponseHeaders().trim().split('\n').forEach(function (item) { - if (item) { - var index = item.indexOf(':'); - var key = item.substr(0, index).trim().toLowerCase(); - var val = item.substr(index + 1).trim(); - headers[key] = val; - } - }); + var strHeaders = xhr.getAllResponseHeaders(); + if (strHeaders && strHeaders.length > 0) { + strHeaders.trim().split('\n').forEach(function (item) { + if (item) { + var index = item.indexOf(':'); + var key = item.substr(0, index).trim().toLowerCase(); + var val = item.substr(index + 1).trim(); + headers[key] = val; + } + }); + } return { error: err, statusCode: xhr.status,