mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 16:08:24 -05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf9ba8c08b | ||
|
|
4e58204b83 | ||
|
|
4308ba8f14 | ||
|
|
0e5fb040a9 | ||
|
|
e62370161d | ||
|
|
5c5b7ee0ba | ||
|
|
4db40d9ecc |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -3,4 +3,4 @@
|
||||
url = git://github.com/visionmedia/js-oo.git
|
||||
[submodule "test/client"]
|
||||
path = test/client
|
||||
url = git@github.com:RosePad/Socket.IO.git
|
||||
url = git://github.com/RosePad/Socket.IO.git
|
||||
|
||||
@@ -12,7 +12,7 @@ The `Socket.IO` server provides seamless supports for a variety of transports in
|
||||
Requirements
|
||||
------------
|
||||
|
||||
- Node v0.1.32+
|
||||
- Node v0.1.32+ (tested with v0.1.32, v0.1.33)
|
||||
- [Socket.IO client](http://github.com/RosePad/Socket.IO) to connect from the browser
|
||||
|
||||
How to use
|
||||
@@ -191,7 +191,7 @@ Despite this extra layer, your messages are delivered unaltered to the different
|
||||
|
||||
## Credits
|
||||
|
||||
Guillermo Rauch [guillermo@rosepad.com]
|
||||
Guillermo Rauch <guillermo@rosepad.com>
|
||||
|
||||
Special thanks to [Jonas Pfenniger](http://github.com/zimbatm) for his workaround patch to keep the HTTPConnection open after the request is successful.
|
||||
|
||||
|
||||
@@ -22,14 +22,18 @@ this.Client = Class({
|
||||
},
|
||||
|
||||
_onMessage: function(data){
|
||||
var messages = JSON.parse(data);
|
||||
try {
|
||||
var messages = JSON.parse(data);
|
||||
} catch(e){
|
||||
return this.listener.options.log('Bad message received from client ' + this.sessionId);
|
||||
}
|
||||
for (var i = 0, l = messages.length; i < l; i++){
|
||||
this.listener._onClientMessage(messages[i], this);
|
||||
}
|
||||
},
|
||||
|
||||
_onConnect: function(req, res){
|
||||
var self = this;
|
||||
var self = this;
|
||||
this.request = req;
|
||||
this.response = res;
|
||||
this.connection = this.request.connection;
|
||||
|
||||
@@ -26,10 +26,6 @@ Listener = this.Listener = Class({
|
||||
this.clients = [];
|
||||
this.clientsIndex = {};
|
||||
|
||||
if (!(this.server instanceof process.http.Server)){
|
||||
throw new Error('Please pass the result of http.createServer() to the listener');
|
||||
}
|
||||
|
||||
var listener = (this.server._events['request'] instanceof Array)
|
||||
? this.server._events['request'][0]
|
||||
: this.server._events['request'];
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var Client = require('../client').Client,
|
||||
url = require('url'),
|
||||
sys = require('sys');
|
||||
url = require('url');
|
||||
|
||||
this.websocket = Client.extend({
|
||||
|
||||
_onConnect: function(req, res){
|
||||
_onConnect: function(req, res){
|
||||
var self = this;
|
||||
this.__super__(req, res);
|
||||
this.__super__(req, res);
|
||||
this.data = '';
|
||||
|
||||
if (this.request.headers['connection'] !== 'Upgrade'
|
||||
|| this.request.headers['upgrade'] !== 'WebSocket'
|
||||
@@ -20,32 +20,44 @@ this.websocket = Client.extend({
|
||||
if (!('hijack' in self.connection)){
|
||||
throw new Error('You have to patch Node! Please refer to the README');
|
||||
}
|
||||
|
||||
|
||||
self.connection.hijack();
|
||||
self.connection.setTimeout(0);
|
||||
self.connection.setEncoding('utf8');
|
||||
self.connection.setNoDelay(true);
|
||||
self.connection.addListener('end', function(){ self._onClose(); });
|
||||
self.connection.addListener('data', function(data){
|
||||
if (data[0] !== '\u0000' && data[data.length - 1] !== '\ufffd'){
|
||||
self.connection.close();
|
||||
} else {
|
||||
self._onMessage(data.substr(1, data.length - 2));
|
||||
}
|
||||
});
|
||||
self.connection.addListener('end', function(){ self._onClose(); });
|
||||
self.connection.addListener('data', function(data){ self._handle(data); });
|
||||
});
|
||||
|
||||
this.response.use_chunked_encoding_by_default = false;
|
||||
this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
|
||||
this.response.writeHeader(101, 'Web Socket Protocol Handshake', {
|
||||
'Upgrade': 'WebSocket',
|
||||
'Connection': 'Upgrade',
|
||||
'WebSocket-Origin': this.request.headers.origin,
|
||||
'WebSocket-Location': 'ws://' + this.request.headers.host + this.request.url
|
||||
});
|
||||
this.response.flush();
|
||||
|
||||
});
|
||||
this.response.flush();
|
||||
this._payload();
|
||||
},
|
||||
|
||||
_handle: function(data){
|
||||
this.data += data;
|
||||
chunks = this.data.split('\ufffd');
|
||||
chunk_count = chunks.length - 1;
|
||||
for (var i = 0; i < chunk_count; i++) {
|
||||
chunk = chunks[i];
|
||||
if (chunk[0] != '\u0000') {
|
||||
this.listener.options.log('Data incorrectly framed by UA. Dropping connection');
|
||||
this.connection.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
this._onMessage(chunk.slice(1));
|
||||
}
|
||||
|
||||
this.data = chunks[chunks.length - 1];
|
||||
},
|
||||
|
||||
_verifyOrigin: function(origin){
|
||||
var parts = url.parse(origin);
|
||||
return this.listener.options.origins.indexOf('*:*') !== -1
|
||||
|
||||
83
patch/0.1.33.patch
Normal file
83
patch/0.1.33.patch
Normal file
@@ -0,0 +1,83 @@
|
||||
diff -rup node-v0.1.32-orig/src/node_http.cc node-v0.1.32/src/node_http.cc
|
||||
--- node-v0.1.32-orig/src/node_http.cc 2010-03-13 13:14:00.000000000 -0800
|
||||
+++ node-v0.1.32/src/node_http.cc 2010-03-13 13:23:48.000000000 -0800
|
||||
@@ -57,6 +57,7 @@ HTTPConnection::Initialize (Handle<Objec
|
||||
client_constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
client_constructor_template->SetClassName(String::NewSymbol("Client"));
|
||||
NODE_SET_PROTOTYPE_METHOD(client_constructor_template, "resetParser", ResetParser);
|
||||
+ NODE_SET_PROTOTYPE_METHOD(client_constructor_template, "hijack", Hijack);
|
||||
target->Set(String::NewSymbol("Client"), client_constructor_template->GetFunction());
|
||||
|
||||
t = FunctionTemplate::New(NewServer);
|
||||
@@ -64,6 +65,7 @@ HTTPConnection::Initialize (Handle<Objec
|
||||
server_constructor_template->Inherit(Connection::constructor_template);
|
||||
server_constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "resetParser", ResetParser);
|
||||
+ NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "hijack", Hijack);
|
||||
server_constructor_template->SetClassName(String::NewSymbol("ServerSideConnection"));
|
||||
|
||||
end_symbol = NODE_PSYMBOL("end");
|
||||
@@ -101,6 +103,14 @@ Handle<Value> HTTPConnection::ResetParse
|
||||
}
|
||||
|
||||
|
||||
+Handle<Value> HTTPConnection::Hijack(const Arguments& args) {
|
||||
+ HandleScope scope;
|
||||
+ HTTPConnection *connection = ObjectWrap::Unwrap<HTTPConnection>(args.Holder());
|
||||
+ connection->Hijack();
|
||||
+ return Undefined();
|
||||
+}
|
||||
+
|
||||
+
|
||||
void
|
||||
HTTPConnection::OnReceive (const void *buf, size_t len)
|
||||
{
|
||||
@@ -109,6 +119,11 @@ HTTPConnection::OnReceive (const void *b
|
||||
assert(refs_);
|
||||
size_t nparsed;
|
||||
|
||||
+ if (hijacked) {
|
||||
+ Connection::OnReceive(buf, len);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
nparsed = http_parser_execute(&parser_, static_cast<const char*>(buf), len);
|
||||
|
||||
if (nparsed != len) {
|
||||
diff -rup node-v0.1.32-orig/src/node_http.h node-v0.1.32/src/node_http.h
|
||||
--- node-v0.1.32-orig/src/node_http.h 2010-03-13 13:14:00.000000000 -0800
|
||||
+++ node-v0.1.32/src/node_http.h 2010-03-13 13:25:05.000000000 -0800
|
||||
@@ -12,17 +12,21 @@ public:
|
||||
static void Initialize (v8::Handle<v8::Object> target);
|
||||
|
||||
static v8::Persistent<v8::FunctionTemplate> client_constructor_template;
|
||||
- static v8::Persistent<v8::FunctionTemplate> server_constructor_template;
|
||||
+ static v8::Persistent<v8::FunctionTemplate> server_constructor_template;
|
||||
|
||||
protected:
|
||||
static v8::Handle<v8::Value> NewClient (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> NewServer (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> ResetParser(const v8::Arguments& args);
|
||||
+ static v8::Handle<v8::Value> Hijack(const v8::Arguments& args);
|
||||
+
|
||||
+ bool hijacked;
|
||||
|
||||
HTTPConnection (enum http_parser_type t)
|
||||
: Connection()
|
||||
{
|
||||
type_ = t;
|
||||
+ hijacked = false;
|
||||
ResetParser();
|
||||
}
|
||||
|
||||
@@ -41,6 +45,10 @@ protected:
|
||||
parser_.data = this;
|
||||
}
|
||||
|
||||
+ void Hijack() {
|
||||
+ hijacked = true;
|
||||
+ }
|
||||
+
|
||||
void OnReceive (const void *buf, size_t len);
|
||||
void OnEOF ();
|
||||
|
||||
Submodule test/client updated: 5cebe02f5d...fd46282c95
Reference in New Issue
Block a user