From fb01a229fca62da6988130d1d3d675b1e712d9a6 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 22 Apr 2026 19:44:09 +0330 Subject: [PATCH] add direct_domains --- config.json | 8 +++++++- proxy_server.py | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index 4922aa6..283cb23 100644 --- a/config.json +++ b/config.json @@ -8,6 +8,12 @@ "listen_port": 8085, "socks5_enabled": true, "socks5_port": 1080, + "direct_domains": [ + "chatgpt.com", + "openai.com", + "oaistatic.com", + "oaiusercontent.com" + ], "log_level": "INFO", "verify_ssl": true -} \ No newline at end of file +} diff --git a/proxy_server.py b/proxy_server.py index 9da9b9f..8190a31 100644 --- a/proxy_server.py +++ b/proxy_server.py @@ -122,6 +122,11 @@ class ProxyServer: # hosts override — DNS fake-map: domain/suffix → IP # Checked before any real DNS lookup; supports exact and suffix matching. self._hosts: dict[str, str] = config.get("hosts", {}) + self._direct_domains: tuple[str, ...] = tuple( + d.lower().lstrip(".").rstrip(".") + for d in config.get("direct_domains", []) + if isinstance(d, str) and d.strip() + ) if self.mode == "apps_script": try: @@ -284,8 +289,8 @@ class ProxyServer: host, override_ip, self.fronter.sni_host) await self._do_sni_rewrite_tunnel(host, port, reader, writer, connect_ip=override_ip) - elif self._is_google_domain(host): - log.info("Direct tunnel → %s (Google domain, skipping relay)", host) + elif self._should_direct_connect(host): + log.info("Direct tunnel → %s (skipping relay)", host) await self._do_direct_tunnel(host, port, reader, writer) else: await self._do_mitm_connect(host, port, reader, writer) @@ -415,6 +420,16 @@ class ProxyServer: return True return False + def _should_direct_connect(self, host: str) -> bool: + """Return True if host should bypass MITM and use raw CONNECT.""" + if self._is_google_domain(host): + return True + h = host.lower().rstrip(".") + for suffix in self._direct_domains: + if h == suffix or h.endswith("." + suffix): + return True + return False + # ── Direct tunnel (no MITM) ─────────────────────────────────── async def _do_direct_tunnel(self, host: str, port: int,