Re: [nodejs] HTTP Response Headers - need to send duplicate headers

Showing 1-1 of 1 messages
Re: [nodejs] HTTP Response Headers - need to send duplicate headers Michael Schoonmaker 10/4/12 7:13 PM
Use an Array in setHeader:

On Thu, Oct 4, 2012 at 1:02 PM, dran yab <> wrote:

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,
        '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',


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:


var aRHEADER = new Array();
var HTTP = require('http');
var ACCEPT_STRING = 'acceptstring';
var IP = '';
var PORT = '80';

HTTP.createServer(function (request , response) {
   var response_data;
   response_data = "Hello world";

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': '',
        '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': '',
        'Sec-WebSocket-Location': 'ws://',
        'Content-Length' : resp_data.length
//end of code

Job Board:
Posting guidelines:
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at