Skip to content

Commit aee4211

Browse files
committed
use url to parse announceUrl
1 parent e55896e commit aee4211

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function Client (peerId, port, torrent, opts) {
5353
if (typeof torrent.announce === 'string') torrent.announce = [ torrent.announce ]
5454
self._trackers = (torrent.announce || [])
5555
.filter(function (announceUrl) {
56-
return announceUrl.indexOf('udp://') === 0 || announceUrl.indexOf('http://') === 0 ||
57-
announceUrl.indexOf('https://') === 0
56+
var protocol = url.parse(announceUrl).protocol
57+
return protocol === 'udp:' || protocol === 'http:' || protocol === 'https:'
5858
})
5959
.map(function (announceUrl) {
6060
return new Tracker(self, announceUrl, self._opts)
@@ -152,10 +152,10 @@ function Tracker (client, announceUrl, opts) {
152152
self._intervalMs = self.client._intervalMs // use client interval initially
153153
self._interval = null
154154

155-
if (self._announceUrl.indexOf('udp://') === 0) {
155+
var protocol = url.parse(self._announceUrl).protocol
156+
if (protocol === 'udp:') {
156157
self._requestImpl = self._requestUdp
157-
} else if (self._announceUrl.indexOf('http://') === 0 ||
158-
self._announceUrl.indexOf('https://') === 0) {
158+
} else if (protocol === 'http:' || protocol === 'https:') {
159159
self._requestImpl = self._requestHttp
160160
}
161161
}
@@ -271,7 +271,7 @@ Tracker.prototype._requestHttp = function (requestUrl, opts) {
271271
var protocol = url.parse(self._announceUrl).protocol
272272
var fullUrl = requestUrl + '?' + common.querystringStringify(opts)
273273

274-
var req = (protocol === 'http:' ? http : https).get(fullUrl, function (res) {
274+
var req = (protocol === 'https:' ? https : http).get(fullUrl, function (res) {
275275
if (res.statusCode !== 200) {
276276
res.resume() // consume the whole stream
277277
self.client.emit('warning', new Error('Invalid response code ' + res.statusCode + ' from tracker ' + requestUrl))

0 commit comments

Comments
 (0)