In electron@5.x
I find an interesting bug.


I set headers with object, but the object type gave Map, so the header think it's not an object
header: function (field, value) {
if (is(field).a(Object)) {
for (var key in field) {
if (Object.prototype.hasOwnProperty.call(field, key)) {
$this.header(key, field[key])
}
}
return $this
}
var existingHeaderName = $this.hasHeader(field)
$this.options.headers[existingHeaderName || field] = value
return $this
},
see the error stack:
name.toLowerCase is not a function
at Object.hasHeader (/Users/xiwz/ynote/electron-sdk/example/node_modules/unirest/index.js:93:21)
at Object.header (/Users/xiwz/ynote/electron-sdk/example/node_modules/unirest/index.js:198:40)
But actually I send the object
{
'Content-Type': '',
'Cookie': ''
}
I think this bug belongs to electron.It changed the Object default behavior. But unirest type check is unsafe.
I wonder if you would like to improve it ? I am willing to send a PR.
My solution:
if (check.prototype) check = Object.prototype.toString.call(check.prototype).slice(8, -1).toLowerCase()
In
electron@5.xI find an interesting bug.
I set headers with object, but the object type gave
Map, so the header think it's not an objectsee the error stack:
But actually I send the object
I think this bug belongs to electron.It changed the Object default behavior. But
uniresttype check is unsafe.I wonder if you would like to improve it ? I am willing to send a PR.
My solution: