aboutsummaryrefslogtreecommitdiff
path: root/src/node_http_parser.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-04-14 03:52:15 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-04-14 03:52:15 -0700
commit760bba55186eba039ca00e532f7813d2aea450a2 (patch)
tree8e9484f5b08cb018204ff26e0d5fb5b3779cd552 /src/node_http_parser.cc
parentaf49187e57105a793ef4abf33339d854f2b5cda2 (diff)
downloadandroid-node-v8-760bba55186eba039ca00e532f7813d2aea450a2.tar.gz
android-node-v8-760bba55186eba039ca00e532f7813d2aea450a2.tar.bz2
android-node-v8-760bba55186eba039ca00e532f7813d2aea450a2.zip
Support Upgrade in HTTP messages
This allows for web servers to be "hijacked" and used as Web Socket servers (or other). You simply listen for requests as normal, but check if req.upgrade === true If so, this will be the last request of the connection. It's your job now to hijack req.connection and start reading from it. req.upgradeHead is a buffer containing the first part of the new protocol communication (in the case it arrived on the same packet). This needs tests and documentation. API subject to change.
Diffstat (limited to 'src/node_http_parser.cc')
-rw-r--r--src/node_http_parser.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index e5dbed38f1..c7e69fc132 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -61,6 +61,7 @@ static Persistent<String> http_version_sym;
static Persistent<String> version_major_sym;
static Persistent<String> version_minor_sym;
static Persistent<String> should_keep_alive_sym;
+static Persistent<String> upgrade_sym;
static struct http_parser_settings settings;
@@ -165,6 +166,8 @@ class Parser : public ObjectWrap {
message_info->Set(should_keep_alive_sym,
http_should_keep_alive(p) ? True() : False());
+ message_info->Set(upgrade_sym, p->upgrade ? True() : False());
+
Local<Value> argv[1] = { message_info };
Local<Value> ret = cb->Call(parser->handle_, 1, argv);
@@ -243,7 +246,7 @@ class Parser : public ObjectWrap {
Local<Integer> nparsed_obj = Integer::New(nparsed);
// If there was a parse error in one of the callbacks
// TODO What if there is an error on EOF?
- if (nparsed != len) {
+ if (!parser->parser_.upgrade && nparsed != len) {
Local<Value> e = Exception::Error(String::New("Parse Error"));
Local<Object> obj = e->ToObject();
obj->Set(String::NewSymbol("bytesParsed"), nparsed_obj);
@@ -345,6 +348,7 @@ void InitHttpParser(Handle<Object> target) {
version_major_sym = NODE_PSYMBOL("versionMajor");
version_minor_sym = NODE_PSYMBOL("versionMinor");
should_keep_alive_sym = NODE_PSYMBOL("shouldKeepAlive");
+ upgrade_sym = NODE_PSYMBOL("upgrade");
settings.on_message_begin = Parser::on_message_begin;
settings.on_path = Parser::on_path;