Permalink
Browse files

Allow passing custom headers.

  • Loading branch information...
1 parent 8188e1f commit 2a366f8aeadfb389d817ba966bf34ec5d599c6f3 @mrunalp committed Jan 30, 2013
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/WebSocket.js
View
@@ -393,7 +393,8 @@ function initAsClient(address, options) {
origin: null,
protocolVersion: protocolVersion,
host: null,
- protocol: null
+ protocol: null,
+ headers: null
}).merge(options);
if (options.value.protocolVersion != 8 && options.value.protocolVersion != 13) {
throw new Error('unsupported protocol version');
@@ -445,6 +446,14 @@ function initAsClient(address, options) {
requestOptions.headers['Host'] = options.value.host;
}
+ if (options.value.headers) {
+ for (var key in options.value.headers) {
+ if (!requestOptions.headers.hasOwnProperty(key)) {
+ requestOptions.headers[key] = options.value.headers[key];
+ }
+ }
+ }
+
if (isNodeV4) {
requestOptions.path = (serverUrl.pathname || '/') + (serverUrl.search || '');
requestOptions.agent = agent;

0 comments on commit 2a366f8

Please sign in to comment.