Skip to content

Commit 23d2c02

Browse files
committed
Support scrape without info_hash specified (Fix webtorrent#28)
1 parent 5bc1b50 commit 23d2c02

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,13 @@ Server.prototype._onHttpRequest = function (req, res) {
220220
} else if (s[0] === '/scrape') { // unofficial scrape message
221221
if (typeof params.info_hash === 'string') {
222222
params.info_hash = [ params.info_hash ]
223+
} else if (params.info_hash == null) {
224+
// if info_hash param is omitted, stats for all torrents are returned
225+
params.info_hash = Object.keys(self.torrents).map(function (infoHashHex) {
226+
return common.bytewiseEncodeURIComponent(new Buffer(infoHashHex, 'hex'))
227+
})
223228
}
229+
224230
if (!Array.isArray(params.info_hash)) return error('invalid info_hash')
225231

226232
var response = {

0 commit comments

Comments
 (0)