From c45cf281fbcfb6f73125e73ef660bef208341852 Mon Sep 17 00:00:00 2001 From: Adam Magaluk Date: Mon, 10 Dec 2018 21:05:43 -0500 Subject: [PATCH] Server forwards `ping` event from the transports Connection. Pass the `ping` event on the transports connection to the server's EventEmitter as the `_ping` event. The event passes the client requests socket to allow users to identify the the socket sending the ping request. --- lib/spdy/server.js | 7 +++++++ test/server-test.js | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/spdy/server.js b/lib/spdy/server.js index 1889fcd..64eb3ec 100644 --- a/lib/spdy/server.js +++ b/lib/spdy/server.js @@ -124,6 +124,13 @@ proto._handleConnection = function _handleConnection (socket, protocol) { connection.start(2) } + // Pass the `ping` event to the server's EventEmitter as` _ping`. Pass the + // socket as an argument to the `_ping` event to allow identifying the + // connection that the ping was emitted from. + connection.on('ping', function () { + self.emit('_ping', socket) + }) + connection.on('error', function () { socket.destroy() }) diff --git a/test/server-test.js b/test/server-test.js index e743055..12e9885 100644 --- a/test/server-test.js +++ b/test/server-test.js @@ -138,6 +138,14 @@ describe('SPDY Server', function () { } }) + it('server should emit _ping event', function (done) { + server.once('_ping', function (socket) { + assert(socket instanceof net.Socket) + done() + }) + client.ping() + }) + it('should process expect-continue request', function (done) { var stream = client.request({ method: 'GET',