Skip to content

Commit 5953841

Browse files
committed
allow user to intercept 'request' event for http tracker
1 parent e77e40b commit 5953841

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ function Server (opts) {
6161
// start an http tracker unless the user explictly says no
6262
if (opts.http !== false) {
6363
self.http = http.createServer()
64-
self.http.on('request', function (req, res) { self.onHttpRequest(req, res) })
6564
self.http.on('error', function (err) { self._onError(err) })
6665
self.http.on('listening', onListening)
66+
67+
// Add default http request handler on next tick to give user the chance to add
68+
// their own handler first. Handle requests untouched by user's handler.
69+
process.nextTick(function () {
70+
self.http.on('request', function (req, res) {
71+
if (res.headersSent) return
72+
self.onHttpRequest(req, res)
73+
})
74+
})
6775
}
6876

6977
// start a udp tracker unless the user explicitly says no

0 commit comments

Comments
 (0)