Skip to content

Commit 4c16d3d

Browse files
committed
Allow setting user agent for http tracker client
1 parent 6cc1be0 commit 4c16d3d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function Client (peerId, port, torrent, opts) {
5353

5454
self._rtcConfig = opts.rtcConfig
5555
self._wrtc = opts.wrtc
56+
self._userAgent = opts.userAgent
5657

5758
debug('new client %s', self._infoHashHex)
5859

lib/client/http-tracker.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ HTTPTracker.prototype.destroy = function (cb) {
8686

8787
HTTPTracker.prototype._request = function (requestUrl, params, cb) {
8888
var self = this
89-
var u = requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') +
89+
var headers = {}
90+
var url = requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') +
9091
common.querystringStringify(params)
9192

92-
get.concat(u, function (err, data, res) {
93+
if (self.client._userAgent) {
94+
headers['User-Agent'] = self.client._userAgent
95+
}
96+
97+
get.concat({ url: url, headers: headers }, function (err, data, res) {
9398
if (self.destroyed) return
9499
if (err) return self.client.emit('warning', err)
95100
if (res.statusCode !== 200) {

0 commit comments

Comments
 (0)