From 5953841466d0fb81773d575f8489979d4090dc4e Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 17 Dec 2015 00:40:46 +1300 Subject: [PATCH] allow user to intercept 'request' event for http tracker --- server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index f61dc3e..03181b7 100644 --- a/server.js +++ b/server.js @@ -61,9 +61,17 @@ function Server (opts) { // start an http tracker unless the user explictly says no if (opts.http !== false) { self.http = http.createServer() - self.http.on('request', function (req, res) { self.onHttpRequest(req, res) }) self.http.on('error', function (err) { self._onError(err) }) self.http.on('listening', onListening) + + // Add default http request handler on next tick to give user the chance to add + // their own handler first. Handle requests untouched by user's handler. + process.nextTick(function () { + self.http.on('request', function (req, res) { + if (res.headersSent) return + self.onHttpRequest(req, res) + }) + }) } // start a udp tracker unless the user explicitly says no