From 9c25a8b47b264459db96cba456e011f654a84a51 Mon Sep 17 00:00:00 2001 From: Eric Guan Date: Mon, 8 Apr 2019 23:49:53 -0700 Subject: [PATCH 1/2] Allows customization of webseed http requests through an options callback function. --- lib/torrent.js | 1 + lib/webconn.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/torrent.js b/lib/torrent.js index 8f667ffe..6c744274 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -72,6 +72,7 @@ class Torrent extends EventEmitter { this.skipVerify = !!opts.skipVerify this._store = opts.store || FSChunkStore this._getAnnounceOpts = opts.getAnnounceOpts + this._getWebseedOpts = opts.getWebseedOpts this.strategy = opts.strategy || 'sequential' diff --git a/lib/webconn.js b/lib/webconn.js index 9c2b461d..039905ad 100644 --- a/lib/webconn.js +++ b/lib/webconn.js @@ -110,7 +110,7 @@ class WebConn extends Wire { 'Requesting url=%s pieceIndex=%d offset=%d length=%d start=%d end=%d', url, pieceIndex, offset, length, start, end ) - const opts = { + let opts = { url, method: 'GET', headers: { @@ -118,6 +118,9 @@ class WebConn extends Wire { range: `bytes=${start}-${end}` } } + if (this._torrent._getWebseedOpts) { + opts = this._torrent._getWebseedOpts(opts) + } function onResponse (res, data) { if (res.statusCode < 200 || res.statusCode >= 300) { hasError = true From f9ab20d1b3ae223c033b5b7b163e8452858b26dd Mon Sep 17 00:00:00 2001 From: Eric Guan Date: Tue, 9 Apr 2019 00:05:05 -0700 Subject: [PATCH 2/2] Fixes Standard linting. --- lib/webconn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webconn.js b/lib/webconn.js index 039905ad..33ed0c9a 100644 --- a/lib/webconn.js +++ b/lib/webconn.js @@ -119,7 +119,7 @@ class WebConn extends Wire { } } if (this._torrent._getWebseedOpts) { - opts = this._torrent._getWebseedOpts(opts) + opts = this._torrent._getWebseedOpts(opts) } function onResponse (res, data) { if (res.statusCode < 200 || res.statusCode >= 300) {