mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-19 04:31:36 +00:00
send 404 response when req headers are not sent
This commit is contained in:
parent
5953841466
commit
4816eb7a41
@ -100,10 +100,13 @@ function Server (opts) {
|
|||||||
self.http.on('error', function (err) { self._onError(err) })
|
self.http.on('error', function (err) { self._onError(err) })
|
||||||
self.http.on('listening', onListening)
|
self.http.on('listening', onListening)
|
||||||
|
|
||||||
// Add default http request handler if user does not add one on same tick
|
// 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 () {
|
process.nextTick(function () {
|
||||||
if (self.http.listenerCount('request') > 0) return
|
|
||||||
self.http.on('request', function (req, res) {
|
self.http.on('request', function (req, res) {
|
||||||
|
if (res.headersSent) return
|
||||||
|
// For websocket trackers, we only need to handle the UPGRADE http method.
|
||||||
|
// Return 404 for all other request types.
|
||||||
res.statusCode = 404
|
res.statusCode = 404
|
||||||
res.end('404 Not Found')
|
res.end('404 Not Found')
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user