Permalink
Browse files

Fixes for htmlfile, multipart, polling

Removed patches
Removed server events
  • Loading branch information...
1 parent c4cf1b2 commit a977ecd65bf53ee1f23d45c7daa5b58b4e280475 @rauchg rauchg committed Apr 30, 2010
@@ -11,7 +11,7 @@ Listener = this.Listener = Class({
options: {
origins: '*:*',
resource: 'socket.io',
- transports: ['websocket', 'server-events', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'],
+ transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'],
timeout: 8000,
log: function(message){
sys.log(message);
@@ -7,17 +7,10 @@ this['htmlfile'] = Client.extend({
switch (req.method){
case 'GET':
var self = this;
- this.__super__(req, res);
- this.request.addListener('end', function(){
- if (!('hijack' in self.connection)){
- throw new Error('You have to patch Node! Please refer to the README');
- }
-
- self.connection.addListener('end', function(){ self._onClose(); });
- self.connection.hijack();
- self.connection.setTimeout(0);
- });
-
+ this.__super__(req, res);
+
+ this.response.useChunkedEncodingByDefault = false;
+ this.response.shouldKeepAlive = true;
this.response.writeHead(200, { 'Content-type': 'text/html' });
this.response.flush();
@@ -26,8 +19,11 @@ this['htmlfile'] = Client.extend({
case 'POST':
req.addListener('data', function(message){
+ body += message;
+ });
+ req.addListener('end', function(){
try {
- var msg = qs.parse(message);
+ var msg = qs.parse(body);
self._onMessage(msg.data);
} catch(e){}
res.writeHead(200);
@@ -1,46 +0,0 @@
-var Client = require('../client').Client,
- qs = require('querystring');
-
-this['server-events'] = Client.extend({
-
- _onConnect: function(req, res){
- switch (req.method){
- case 'GET':
- var self = this;
- this.__super__(req, res);
- this.request.addListener('end', function(){
- if (!('hijack' in self.connection)){
- throw new Error('You have to patch Node! Please refer to the README');
- }
-
- self.connection.addListener('end', function(){ self._onClose(); });
- self.connection.hijack();
- self.connection.setTimeout(0);
- });
-
- this.response.writeHead(200, { 'Content-type': 'application/x-dom-event-stream' });
- this.response.flush();
-
- this._payload();
- break;
-
- case 'POST':
- req.addListener('data', function(message){
- try {
- var msg = qs.parse(message);
- self._onMessage(msg.data);
- } catch(e){}
- res.writeHead(200);
- res.write('ok');
- res.end();
- });
- break;
- }
- },
-
- _write: function(message){
- this.response.write("Event: socket.io");
- this.response.write("data: " + message);
- }
-
-});
@@ -4,22 +4,14 @@ var Client = require('../client').Client,
this['xhr-multipart'] = Client.extend({
_onConnect: function(req, res){
- var self = this;
+ var self = this, body = '';
switch (req.method){
case 'GET':
var self = this;
this.__super__(req, res);
- this.request.addListener('end', function(){
- if (!('hijack' in self.connection)){
- throw new Error('You have to patch Node! Please refer to the README');
- }
- self.connection.addListener('end', function(){ self._onClose(); });
- self.connection.hijack();
- self.connection.setTimeout(0);
- });
-
- this.response.use_chunked_encoding_by_default = false;
+ this.response.useChunkedEncodingByDefault = false;
+ this.response.shouldKeepAlive = true;
this.response.writeHead(200, {
'Content-Type': 'multipart/x-mixed-replace;boundary=socketio',
'Connection': 'keep-alive'
@@ -32,8 +24,11 @@ this['xhr-multipart'] = Client.extend({
case 'POST':
req.addListener('data', function(message){
+ body += message;
+ });
+ req.addListener('end', function(){
try {
- var msg = qs.parse(message);
+ var msg = qs.parse(body);
self._onMessage(msg.data);
} catch(e){}
res.writeHead(200);
@@ -21,8 +21,11 @@ this['xhr-polling'] = Client.extend({
case 'POST':
req.addListener('data', function(message){
+ body += message;
+ });
+ req.addListener('end', function(){
try {
- var msg = qs.parse(message);
+ var msg = qs.parse(body);
self._onMessage(msg.data);
} catch(e){}
res.writeHead(200);
View
@@ -1,83 +0,0 @@
-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 ();
-
View
@@ -1,83 +0,0 @@
-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 ();
-

0 comments on commit a977ecd

Please sign in to comment.