diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-04-14 03:52:15 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-04-14 03:52:15 -0700 |
commit | 760bba55186eba039ca00e532f7813d2aea450a2 (patch) | |
tree | 8e9484f5b08cb018204ff26e0d5fb5b3779cd552 /src/node_http_parser.cc | |
parent | af49187e57105a793ef4abf33339d854f2b5cda2 (diff) | |
download | android-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.cc | 6 |
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; |