diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/env.h | 1 | ||||
-rw-r--r-- | src/node_http2.cc | 17 |
2 files changed, 13 insertions, 5 deletions
@@ -229,6 +229,7 @@ struct PackageConfig { V(onread_string, "onread") \ V(onreadstart_string, "onreadstart") \ V(onreadstop_string, "onreadstop") \ + V(onping_string, "onping") \ V(onsettings_string, "onsettings") \ V(onshutdown_string, "onshutdown") \ V(onsignal_string, "onsignal") \ diff --git a/src/node_http2.cc b/src/node_http2.cc index 837d58c81c..7dc695ba79 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1457,6 +1457,11 @@ void Http2Session::HandleOriginFrame(const nghttp2_frame* frame) { // Called by OnFrameReceived when a complete PING frame has been received. void Http2Session::HandlePingFrame(const nghttp2_frame* frame) { + Isolate* isolate = env()->isolate(); + HandleScope scope(isolate); + Local<Context> context = env()->context(); + Context::Scope context_scope(context); + Local<Value> arg; bool ack = frame->hd.flags & NGHTTP2_FLAG_ACK; if (ack) { Http2Ping* ping = PopPing(); @@ -1468,13 +1473,15 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) { // receive an unsolicited PING ack on a connection. Either the peer // is buggy or malicious, and we're not going to tolerate such // nonsense. - Isolate* isolate = env()->isolate(); - HandleScope scope(isolate); - Local<Context> context = env()->context(); - Context::Scope context_scope(context); - Local<Value> arg = Integer::New(isolate, NGHTTP2_ERR_PROTO); + arg = Integer::New(isolate, NGHTTP2_ERR_PROTO); MakeCallback(env()->error_string(), 1, &arg); } + } else { + // Notify the session that a ping occurred + arg = Buffer::Copy(env(), + reinterpret_cast<const char*>(frame->ping.opaque_data), + 8).ToLocalChecked(); + MakeCallback(env()->onping_string(), 1, &arg); } } |