error http request at headers is array
- Version: v6.2.1
- Platform: ubuntu 14
test case
var http = require("http");
var headersArray = [
['Host','echo.websocket.org'],
['Connection','Upgrade'],
['Upgrade','websocket'],
['Origin','http://www.websocket.org'],
];
var headersObj = {
'Host':'echo.websocket.org',
'Connection':'Upgrade',
'Upgrade':'websocket',
'Origin':'http://www.websocket.org'
};
var req = http.request({
method: "GET",
host: "echo.websocket.org" ,
path: "ws://echo.websocket.org/?encoding=text",
headers: headersArray
});
req.on('response',function(res){
console.log('response' , res.headers);
});
req.on('upgrade',function(res){
console.log('upgrade',res.headers);
});
req.end();
error output
_http_common.js:92
(parser.outgoing._headers.upgrade === undefined ||
^
TypeError: Cannot read property 'upgrade' of null
at HTTPParser.parserOnHeadersComplete (_http_common.js:92:32)
at Socket.socketOnData (_http_client.js:359:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:542:20)
@disharmonized Why has this line ? https://github.com/nodejs/node/blob/v6.4.0/lib/_http_client.js#L124
this code work well
var http = require("http");
var headersArray = [
['Host','echo.websocket.org'],
['Connection','Upgrade'],
// ['Upgrade','websocket'],
['Origin','http://www.websocket.org'],
];
var req = http.request({
method: "GET",
host: "echo.websocket.org" ,
path: "ws://echo.websocket.org/?encoding=text",
headers: headersArray
});
req.on('response',function(res){
console.log('response' , res.headers);
});
req.on('upgrade',function(res){
console.log('upgrade',res.headers);
});
req.end();
Hmm, interesting...
You really should use the documented API for headers (objects, not arrays). Nonetheless, I have a fix for this in #8238.
Array is only way to send duplicate headers. without nodejs merge them.
What server requires duplicate HTTP headers?
For proxy server. There are many browsers and software and servers that not meet the standards.