I am attempting to write RFC-6455 compliant websockets server is node.js
and in order for this to work, node.js must allow me to send some
duplicated response headers.
Here are the headers I need to send:
'Connection: Upgrade',
'Sec-WebSocket-Accept: ACCEPT_STRING,
'Server: www.safepeers.com',
'Access-Control-Allow-Credentials: true',
'Access-Control-Allow-Headers: content-type',
'Access-Control-Allow-Headers: authorization',
'Access-Control-Allow-Headers: x-websocket-extensions',
'Access-Control-Allow-Headers: x-websocket-version',
'Access-Control-Allow-Headers: x-websocket-protocol',
'Sec-WebSocket-Origin: http://192.168.1.122',
Note above, the 'Access-Control-Allow-Headers' is defined 5 times above
with each instance containing a different value.
When using "*response.writeHead(200,my_header_above)*", node.js sends most
above headers normally, except 'Access-Control-Allow-Headers:...' headers,
it only sends one instance (the last one) instead of all 5. Presumably
because the duplicated header is simply over-written with each subsequent
variation in the list.
(I know there are libs already written to support websockets for node.js,
but I need to write this one for a special custom application in which the
currently available websocket libs cannot be used.)
So, is there any way in node.js to send this header 5 times, as it is
defined above?
Below is a working example of the code I used to discover this perceived
limitation:
// BEGINNINGS OF A WEBSOCKETS SERVER
var aRHEADER = new Array();
var HTTP = require('http');
var ACCEPT_STRING = 'acceptstring';
var IP = '192.168.1.1';
var PORT = '80';
HTTP.createServer(function (request , response) {
var response_data;
response_data = "Hello world";
set_response_header(response_data)
response.writeHead(200,aRHEADER);
response.write(response_data);
response.end();
}).listen(PORT,IP);
console.log('Server listening on: IP:'+IP+') PORT:'+PORT);
function set_response_header(resp_data) {
aRHEADER = {
'Upgrade': 'WebSocket',
'Connection': 'Upgrade',
'Sec-WebSocket-Accept': ACCEPT_STRING,
'Server': 'www.safepeers.com',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': 'content-type',
'Access-Control-Allow-Headers': 'authorization',
'Access-Control-Allow-Headers': 'x-websocket-extensions',
'Access-Control-Allow-Headers': 'x-websocket-version',
'Access-Control-Allow-Headers': 'x-websocket-protocol',
'Sec-WebSocket-Origin': 'http://192.168.1.122',
'Sec-WebSocket-Location': 'ws://192.168.1.122:5222',
'Content-Length' : resp_data.length
};
}
//end of code
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en