|
| 1 | +From 37a975b92da63d9141690d379adfeb827dbd097c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Pfenniger Jonas < [email protected]> |
| 3 | +Date: Fri, 25 Dec 2009 23:51:00 +0100 |
| 4 | +Subject: [PATCH] Added hijack method to http.Request.prototype.connection |
| 5 | + |
| 6 | +--- |
| 7 | + src/node_http.cc | 14 ++++++++++++++ |
| 8 | + src/node_http.h | 8 ++++++++ |
| 9 | + 2 files changed, 22 insertions(+), 0 deletions(-) |
| 10 | + |
| 11 | +diff --git a/src/node_http.cc b/src/node_http.cc |
| 12 | +index 5ccc53b..b5f9dd8 100644 |
| 13 | +--- a/src/node_http.cc |
| 14 | ++++ b/src/node_http.cc |
| 15 | +@@ -40,6 +40,7 @@ HTTPConnection::Initialize (Handle<Object> target) |
| 16 | + client_constructor_template->InstanceTemplate()->SetInternalFieldCount(1); |
| 17 | + client_constructor_template->SetClassName(String::NewSymbol("Client")); |
| 18 | + NODE_SET_PROTOTYPE_METHOD(client_constructor_template, "resetParser", ResetParser); |
| 19 | ++ NODE_SET_PROTOTYPE_METHOD(client_constructor_template, "hijack", Hijack); |
| 20 | + target->Set(String::NewSymbol("Client"), client_constructor_template->GetFunction()); |
| 21 | + |
| 22 | + t = FunctionTemplate::New(NewServer); |
| 23 | +@@ -47,6 +48,7 @@ HTTPConnection::Initialize (Handle<Object> target) |
| 24 | + server_constructor_template->Inherit(Connection::constructor_template); |
| 25 | + server_constructor_template->InstanceTemplate()->SetInternalFieldCount(1); |
| 26 | + NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "resetParser", ResetParser); |
| 27 | ++ NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "hijack", Hijack); |
| 28 | + server_constructor_template->SetClassName(String::NewSymbol("ServerSideConnection")); |
| 29 | + |
| 30 | + method_symbol = NODE_PSYMBOL("method"); |
| 31 | +@@ -85,6 +87,13 @@ Handle<Value> HTTPConnection::ResetParser(const Arguments& args) { |
| 32 | + return Undefined(); |
| 33 | + } |
| 34 | + |
| 35 | ++Handle<Value> HTTPConnection::Hijack(const Arguments& args) { |
| 36 | ++ HandleScope scope; |
| 37 | ++ HTTPConnection *connection = ObjectWrap::Unwrap<HTTPConnection>(args.Holder()); |
| 38 | ++ connection->Hijack(); |
| 39 | ++ return Undefined(); |
| 40 | ++} |
| 41 | ++ |
| 42 | + |
| 43 | + void |
| 44 | + HTTPConnection::OnReceive (const void *buf, size_t len) |
| 45 | +@@ -94,6 +103,11 @@ HTTPConnection::OnReceive (const void *buf, size_t len) |
| 46 | + assert(refs_); |
| 47 | + size_t nparsed; |
| 48 | + |
| 49 | ++ if (hijacked) { |
| 50 | ++ Connection::OnReceive(buf, len); |
| 51 | ++ return; |
| 52 | ++ } |
| 53 | ++ |
| 54 | + if (type_ == HTTP_REQUEST) { |
| 55 | + nparsed = http_parse_requests(&parser_, static_cast<const char*>(buf), len); |
| 56 | + } else { |
| 57 | +diff --git a/src/node_http.h b/src/node_http.h |
| 58 | +index 1e36df0..f8b1112 100644 |
| 59 | +--- a/src/node_http.h |
| 60 | ++++ b/src/node_http.h |
| 61 | +@@ -20,11 +20,15 @@ protected: |
| 62 | + static v8::Handle<v8::Value> NewClient (const v8::Arguments& args); |
| 63 | + static v8::Handle<v8::Value> NewServer (const v8::Arguments& args); |
| 64 | + static v8::Handle<v8::Value> ResetParser(const v8::Arguments& args); |
| 65 | ++ static v8::Handle<v8::Value> Hijack(const v8::Arguments& args); |
| 66 | ++ |
| 67 | ++ bool hijacked; |
| 68 | + |
| 69 | + HTTPConnection (enum http_connection_type t) |
| 70 | + : Connection() |
| 71 | + { |
| 72 | + type_ = t; |
| 73 | ++ hijacked = false; |
| 74 | + ResetParser(); |
| 75 | + } |
| 76 | + |
| 77 | +@@ -42,6 +46,10 @@ protected: |
| 78 | + parser_.on_message_complete = on_message_complete; |
| 79 | + parser_.data = this; |
| 80 | + } |
| 81 | ++ |
| 82 | ++ void Hijack() { |
| 83 | ++ hijacked = true; |
| 84 | ++ } |
| 85 | + |
| 86 | + void OnReceive (const void *buf, size_t len); |
| 87 | + void OnEOF (); |
| 88 | +-- |
| 89 | +1.6.6 |
| 90 | + |
0 commit comments