diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2014-12-31 09:25:09 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2014-12-31 12:08:01 +0300 |
commit | 889e04156709321ff694679b7ea064f18bbb08e3 (patch) | |
tree | a6e58dc3875b8168f2a34e4d9e3afa5e0674eadb | |
parent | 5f8482e1eed7c22f51e08db52abe2d4358f04b9a (diff) |
Use 'WebTorrent' user-agent for http requests
Fixes #229
-rw-r--r-- | index.js | 4 | ||||
-rw-r--r-- | lib/torrent.js | 5 | ||||
-rw-r--r-- | test/basic-node.js | 3 |
3 files changed, 9 insertions, 3 deletions
@@ -79,7 +79,9 @@ function WebTorrent (opts) { debug('new webtorrent (peerId %s, nodeId %s)', self.peerIdHex, self.nodeIdHex) if (typeof loadIPSet === 'function') { - loadIPSet(opts.blocklist, function (err, ipSet) { + loadIPSet(opts.blocklist, { + headers: { 'user-agent': 'WebTorrent (http://webtorrent.io)' } + }, function (err, ipSet) { self.blocked = ipSet ready() }) diff --git a/lib/torrent.js b/lib/torrent.js index db8c33f..e6bd82e 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -79,7 +79,10 @@ function Torrent (torrentId, opts) { } else if (typeof get === 'function' && /^https?:/.test(torrentId)) { // http or https url to torrent file - get(torrentId, function (err, res) { + get({ + url: torrentId, + headers: { 'user-agent': 'WebTorrent (http://webtorrent.io)' } + }, function (err, res) { if (err) return self.emit('error', new Error('error downloading torrent: ' + err.message)) res.pipe(concat(onTorrentId)) diff --git a/test/basic-node.js b/test/basic-node.js index ad269f0..614bdbe 100644 --- a/test/basic-node.js +++ b/test/basic-node.js @@ -13,9 +13,10 @@ var numbersPath = __dirname + '/content/numbers' var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce' test('client.add (http url to a torrent file (string))', function (t) { - t.plan(2) + t.plan(3) var server = http.createServer(function (req, res) { + t.equal(req.headers['user-agent'], 'WebTorrent (http://webtorrent.io)') res.end(leaves) }) |