@@ -3,12 +3,23 @@ const bencode = require('bencode')
33const compact2string = require ( 'compact2string' )
44const debug = require ( 'debug' ) ( 'bittorrent-tracker:http-tracker' )
55const get = require ( 'simple-get' )
6+ const querystring = require ( 'querystring-browser' )
67
78const common = require ( '../common' )
89const Tracker = require ( './tracker' )
910
1011const HTTP_SCRAPE_SUPPORT = / \/ ( a n n o u n c e ) [ ^ / ] * $ /
1112
13+ const REQUEST_TIMEOUT = 15000
14+ const DESTROY_TIMEOUT = 1000
15+
16+ const querystringStringify = obj => {
17+ let ret = querystring . stringify ( obj , null , null , { encodeURIComponent : escape } )
18+ ret = ret . replace ( / [ @ * / + ] / g, char => // `escape` doesn't encode the characters @*/+ so we do it manually
19+ `%${ char . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) } ` )
20+ return ret
21+ }
22+
1223/**
1324 * HTTP torrent tracker client (for an individual tracker)
1425 *
@@ -86,7 +97,7 @@ class HTTPTracker extends Tracker {
8697
8798 // Otherwise, wait a short time for pending requests to complete, then force
8899 // destroy them.
89- timeout = setTimeout ( destroyCleanup , common . DESTROY_TIMEOUT )
100+ timeout = setTimeout ( destroyCleanup , DESTROY_TIMEOUT )
90101
91102 // But, if all pending requests complete before the timeout fires, do cleanup
92103 // right away.
@@ -111,13 +122,13 @@ class HTTPTracker extends Tracker {
111122 _request ( requestUrl , params , cb ) {
112123 const self = this
113124 const u = requestUrl + ( ! requestUrl . includes ( '?' ) ? '?' : '&' ) +
114- common . querystringStringify ( params )
125+ querystringStringify ( params )
115126
116127 this . cleanupFns . push ( cleanup )
117128
118129 let request = get . concat ( {
119130 url : u ,
120- timeout : common . REQUEST_TIMEOUT ,
131+ timeout : REQUEST_TIMEOUT ,
121132 headers : {
122133 'user-agent' : this . client . _userAgent || ''
123134 }
0 commit comments