server _onHttpRequest(): ensure non-empty params

This commit is contained in:
Astro 2014-12-11 16:22:17 +01:00
parent e64fecc063
commit 74d9139049

View File

@ -127,21 +127,26 @@ Server.prototype.getSwarm = function (binaryInfoHash) {
Server.prototype._onHttpRequest = function (req, res) { Server.prototype._onHttpRequest = function (req, res) {
var self = this var self = this
var error
var params var params
try { try {
params = parseHttpRequest(req, { params = parseHttpRequest(req, {
trustProxy: self._trustProxy trustProxy: self._trustProxy
}) })
} catch (err) { } catch (err) {
debug('sent error %s', err.message) error = err
}
if (!error && !params) error = new Error('Empty HTTP parameters')
if (error) {
debug('sent error %s', error.message)
res.end(bencode.encode({ res.end(bencode.encode({
'failure reason': err.message 'failure reason': error.message
})) }))
// even though it's an error for the client, it's just a warning for the server. // even though it's an error for the client, it's just a warning for the server.
// don't crash the server because a client sent bad data :) // don't crash the server because a client sent bad data :)
self.emit('warning', err) self.emit('warning', error)
return return
} }