@@ -11,6 +11,7 @@ var EventEmitter = require('events').EventEmitter
1111var extend = require ( 'extend.js' )
1212var hat = require ( 'hat' )
1313var http = require ( 'http' )
14+ var https = require ( 'https' )
1415var inherits = require ( 'inherits' )
1516var once = require ( 'once' )
1617var url = require ( 'url' )
@@ -52,7 +53,8 @@ function Client (peerId, port, torrent, opts) {
5253 if ( typeof torrent . announce === 'string' ) torrent . announce = [ torrent . announce ]
5354 self . _trackers = ( torrent . announce || [ ] )
5455 . filter ( function ( announceUrl ) {
55- return announceUrl . indexOf ( 'udp://' ) === 0 || announceUrl . indexOf ( 'http://' ) === 0
56+ var protocol = url . parse ( announceUrl ) . protocol
57+ return protocol === 'udp:' || protocol === 'http:' || protocol === 'https:'
5658 } )
5759 . map ( function ( announceUrl ) {
5860 return new Tracker ( self , announceUrl , self . _opts )
@@ -150,9 +152,10 @@ function Tracker (client, announceUrl, opts) {
150152 self . _intervalMs = self . client . _intervalMs // use client interval initially
151153 self . _interval = null
152154
153- if ( self . _announceUrl . indexOf ( 'udp://' ) === 0 ) {
155+ var protocol = url . parse ( self . _announceUrl ) . protocol
156+ if ( protocol === 'udp:' ) {
154157 self . _requestImpl = self . _requestUdp
155- } else if ( self . _announceUrl . indexOf ( 'http://' ) === 0 ) {
158+ } else if ( protocol === 'http:' || protocol === 'https:' ) {
156159 self . _requestImpl = self . _requestHttp
157160 }
158161}
@@ -265,9 +268,10 @@ Tracker.prototype._requestHttp = function (requestUrl, opts) {
265268 }
266269 }
267270
271+ var protocol = url . parse ( self . _announceUrl ) . protocol
268272 var fullUrl = requestUrl + '?' + common . querystringStringify ( opts )
269273
270- var req = http . get ( fullUrl , function ( res ) {
274+ var req = ( protocol === 'https:' ? https : http ) . get ( fullUrl , function ( res ) {
271275 if ( res . statusCode !== 200 ) {
272276 res . resume ( ) // consume the whole stream
273277 self . client . emit ( 'warning' , new Error ( 'Invalid response code ' + res . statusCode + ' from tracker ' + requestUrl ) )
0 commit comments