Skip to content

Commit 2088198

Browse files
authored
fix: getAllResponseHeaders 可能返回null (#196)
1 parent 5a0934f commit 2088198

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/request.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ var queryStringify = function(obj, sep, eq, name) {
3737

3838
var xhrRes = function (err, xhr, body) {
3939
var headers = {};
40-
xhr.getAllResponseHeaders().trim().split('\n').forEach(function (item) {
41-
if (item) {
42-
var index = item.indexOf(':');
43-
var key = item.substr(0, index).trim().toLowerCase();
44-
var val = item.substr(index + 1).trim();
45-
headers[key] = val;
46-
}
47-
});
40+
var strHeaders = xhr.getAllResponseHeaders();
41+
if (strHeaders && strHeaders.length > 0) {
42+
strHeaders.trim().split('\n').forEach(function (item) {
43+
if (item) {
44+
var index = item.indexOf(':');
45+
var key = item.substr(0, index).trim().toLowerCase();
46+
var val = item.substr(index + 1).trim();
47+
headers[key] = val;
48+
}
49+
});
50+
}
4851
return {
4952
error: err,
5053
statusCode: xhr.status,

0 commit comments

Comments
 (0)