11import arrayRemove from 'unordered-array-remove'
22import bencode from 'bencode'
33import Debug from 'debug'
4- import fetch from 'cross-fetch-ponyfill'
4+ import { serverProxyFetch as fetch } from '@fkn/lib'
5+ // import fetch from 'cross-fetch-ponyfill'
56import { bin2hex , hex2bin , arr2text , text2arr , arr2hex } from 'uint8-util'
67
78import common from '../common.js'
@@ -28,6 +29,7 @@ function abortTimeout (ms) {
2829 */
2930class HTTPTracker extends Tracker {
3031 constructor ( client , announceUrl ) {
32+ console . log ( 'HTTP TRACKER CREATED' , client , announceUrl )
3133 super ( client , announceUrl )
3234
3335 debug ( 'new http tracker %s' , announceUrl )
@@ -119,7 +121,15 @@ class HTTPTracker extends Tracker {
119121 }
120122
121123 async _request ( requestUrl , params , cb ) {
122- const parsedUrl = new URL ( requestUrl + ( requestUrl . indexOf ( '?' ) === - 1 ? '?' : '&' ) + common . querystringStringify ( params ) )
124+ const _parsedUrl = new URL ( requestUrl + ( requestUrl . indexOf ( '?' ) === - 1 ? '?' : '&' ) + common . querystringStringify ( params ) )
125+ const parsedUrl = new URL ( _parsedUrl . toString ( ) )
126+ parsedUrl . searchParams . set (
127+ 'info_hash' ,
128+ new URLSearchParams ( { info_hash : escape ( params . info_hash ) } )
129+ . toString ( )
130+ . replaceAll ( '%25' , '%' )
131+ . replace ( 'info_hash=' , '' )
132+ )
123133 let agent
124134 if ( this . client . _proxyOpts ) {
125135 agent = parsedUrl . protocol === 'https:' ? this . client . _proxyOpts . httpsAgent : this . client . _proxyOpts . httpAgent
@@ -142,7 +152,7 @@ class HTTPTracker extends Tracker {
142152 let res
143153 let controller = abortTimeout ( common . REQUEST_TIMEOUT )
144154 try {
145- res = await fetch ( parsedUrl . toString ( ) , {
155+ res = await fetch ( parsedUrl . toString ( ) . replaceAll ( '%25' , '%' ) , {
146156 agent,
147157 signal : controller . signal ,
148158 dispatcher : agent ,
0 commit comments