Files
worldmonitor/scripts/_proxy-utils.cjs
Elie Habib 15bd6f31ca refactor: consolidate proxy tunnel into shared _proxy-utils.cjs (#2702)
* refactor: consolidate 5 proxy tunnel implementations into _proxy-utils.cjs

5 near-identical HTTP CONNECT proxy tunnel implementations (3 in
ais-relay.cjs, 1 in _seed-utils.mjs, 1 in seed-military-flights.mjs)
consolidated into two shared functions in _proxy-utils.cjs:

- proxyConnectTunnel(): low-level CONNECT + TLS wrapping, returns socket
- proxyFetch(): high-level fetch with decompression, custom headers,
  POST support, timeout

All consumers now call the shared implementation:
- _seed-utils.mjs httpsProxyFetchRaw: 75 lines -> 6 lines
- ais-relay.cjs ytFetchViaProxy: 40 lines -> 5 lines
- ais-relay.cjs _openskyProxyConnect: 35 lines -> 8 lines
- ais-relay.cjs inline Dodo CONNECT: 25 lines -> 10 lines
- seed-military-flights.mjs proxyFetchJson: 70 lines -> 14 lines

Also wires weather alerts proxy fallback (fixes STALE_SEED health crit).

Net: -104 lines. Resolves the TODO at _seed-utils.mjs:311.

* fix(proxy): default tls=true for bare proxy strings

parseProxyConfig returned no tls field for bare-format proxies
(user:pass@host:port and host:port:user:pass). proxyConnectTunnel
checked proxyConfig.tls and used plain TCP when it was undefined,
breaking connections to Decodo which requires TLS. Only http:// URLs
should use plain TCP.

* fix(proxy): timeout covers full response, pass targetPort through

- Move clearTimeout from header arrival to stream end, so a server
  that stalls after 200 OK headers still hits the timeout
- Make targetPort configurable in proxyConnectTunnel (was hardcoded
  443), pass through from _openskyProxyConnect
2026-04-05 08:01:27 +04:00

7.2 KiB