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 '
55import { bin2hex , hex2bin , arr2text , text2arr , arr2hex } from 'uint8-util'
66
77import common from '../common.js'
@@ -121,7 +121,36 @@ class HTTPTracker extends Tracker {
121121 }
122122
123123 async _request ( requestUrl , params , cb ) {
124- const parsedUrl = new URL ( requestUrl + ( requestUrl . indexOf ( '?' ) === - 1 ? '?' : '&' ) + common . querystringStringify ( params ) )
124+ const parsedUrl = new URL (
125+ requestUrl +
126+ ( requestUrl . indexOf ( '?' ) === - 1 ? '?' : '&' ) +
127+ common . querystringStringify (
128+ Object . fromEntries (
129+ Object
130+ . entries ( params )
131+ . filter ( ( [ _ , value ] ) =>
132+ ! (
133+ value === undefined
134+ || value === null
135+ || value === ''
136+ || (
137+ typeof value === 'number'
138+ && isNaN ( value )
139+ )
140+ )
141+ )
142+ )
143+ )
144+ )
145+
146+ parsedUrl . searchParams . set (
147+ 'info_hash' ,
148+ new URLSearchParams ( { info_hash : escape ( params . info_hash ) } )
149+ . toString ( )
150+ . replaceAll ( '%25' , '%' )
151+ . replace ( 'info_hash=' , '' )
152+ )
153+
125154 let agent
126155 if ( this . client . _proxyOpts ) {
127156 agent = parsedUrl . protocol === 'https:' ? this . client . _proxyOpts . httpsAgent : this . client . _proxyOpts . httpAgent
@@ -144,7 +173,7 @@ class HTTPTracker extends Tracker {
144173 let res
145174 let controller = abortTimeout ( common . REQUEST_TIMEOUT )
146175 try {
147- res = await fetch ( parsedUrl . toString ( ) , {
176+ res = await fetch ( parsedUrl . toString ( ) . replaceAll ( '%25' , '%' ) , {
148177 agent,
149178 signal : controller . signal ,
150179 dispatcher : agent ,
0 commit comments