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,