From 2960458825a31def9e5cf2bbf02cd5a7912d5661 Mon Sep 17 00:00:00 2001 From: Username Date: Sun, 15 Feb 2026 03:58:57 +0100 Subject: [PATCH] httpd: fix wsgi /proxies route ignoring query params The WSGI _handle_route had a hardcoded LIMIT 100 query for /proxies, ignoring limit, proto, country, asn, and format parameters. Align with the BaseHTTPRequestHandler path that already supported them. --- httpd.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/httpd.py b/httpd.py index 8432312..d60e586 100644 --- a/httpd.py +++ b/httpd.py @@ -1392,12 +1392,33 @@ class ProxyAPIServer(threading.Thread): return json.dumps({'error': str(e)}), 'application/json', 500 elif path == '/proxies': try: + limit = min(int(query_params.get('limit', 100)), 1000) + proto = query_params.get('proto', '') + country = query_params.get('country', '') + asn = query_params.get('asn', '') + fmt = query_params.get('format', 'json') + + sql = 'SELECT ip, port, proto, country, asn, avg_latency FROM proxylist WHERE failed=0' + args = [] + if proto: + sql += ' AND proto=?' + args.append(proto) + if country: + sql += ' AND country=?' + args.append(country.upper()) + if asn: + sql += ' AND asn=?' + args.append(int(asn)) + sql += ' ORDER BY avg_latency ASC, tested DESC LIMIT ?' + args.append(limit) + db = mysqlite.mysqlite(self.database, str) - rows = db.execute( - 'SELECT proxy, proto, country, asn FROM proxylist WHERE failed=0 LIMIT 100' - ).fetchall() - proxies = [{'proxy': r[0], 'proto': r[1], 'country': r[2], 'asn': r[3]} for r in rows] - return json.dumps({'proxies': proxies}, indent=2), 'application/json', 200 + rows = db.execute(sql, args).fetchall() + + if fmt == 'plain': + return '\n'.join('%s:%s' % (r[0], r[1]) for r in rows), 'text/plain', 200 + proxies = [{'proxy': '%s:%s' % (r[0], r[1]), 'proto': r[2], 'country': r[3], 'asn': r[4], 'latency': r[5]} for r in rows] + return json.dumps({'count': len(proxies), 'proxies': proxies}, indent=2), 'application/json', 200 except Exception as e: return json.dumps({'error': str(e)}), 'application/json', 500 elif path == '/proxies/count':