Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add 'opts' param to WebSocket(); set Origin hdr.

Closes #2

- Fix inspired by nick@quaran.to.
  • Loading branch information...
commit 9908f3f1b0d284ce0ae2cdd799bd895182f6c878 1 parent d45951d
@pgriess authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/websocket.js
View
10 lib/websocket.js
@@ -171,7 +171,7 @@ var setConstant = function(obj, name, value) {
//
// N.B. Arguments are parsed in the anonymous function at the bottom of the
// constructor.
-var WebSocket = function(url, proto) {
+var WebSocket = function(url, proto, opts) {
events.EventEmitter.call(this);
// Retain a reference to our object
@@ -183,6 +183,10 @@ var WebSocket = function(url, proto) {
// Our underlying net.Stream instance
var stream = undefined;
+ opts = opts || {
+ origin : 'http://www.example.com'
+ };
+
// Frame parsing functions
//
// These read data from the given buffer starting at the given offset look
@@ -412,6 +416,10 @@ var WebSocket = function(url, proto) {
'Sec-WebSocket-Key1' : key1,
'Sec-WebSocket-Key2' : key2
};
+ if (opts.origin) {
+ httpHeaders['Origin'] = opts.origin;
+ }
+
var httpPath = '/';
if (proto) {

1 comment on commit 9908f3f

@qrush

Woot, good idea.

Please sign in to comment.
Something went wrong with that request. Please try again.