add direct_domains
This commit is contained in:
+7
-1
@@ -8,6 +8,12 @@
|
|||||||
"listen_port": 8085,
|
"listen_port": 8085,
|
||||||
"socks5_enabled": true,
|
"socks5_enabled": true,
|
||||||
"socks5_port": 1080,
|
"socks5_port": 1080,
|
||||||
|
"direct_domains": [
|
||||||
|
"chatgpt.com",
|
||||||
|
"openai.com",
|
||||||
|
"oaistatic.com",
|
||||||
|
"oaiusercontent.com"
|
||||||
|
],
|
||||||
"log_level": "INFO",
|
"log_level": "INFO",
|
||||||
"verify_ssl": true
|
"verify_ssl": true
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-2
@@ -122,6 +122,11 @@ class ProxyServer:
|
|||||||
# hosts override — DNS fake-map: domain/suffix → IP
|
# hosts override — DNS fake-map: domain/suffix → IP
|
||||||
# Checked before any real DNS lookup; supports exact and suffix matching.
|
# Checked before any real DNS lookup; supports exact and suffix matching.
|
||||||
self._hosts: dict[str, str] = config.get("hosts", {})
|
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":
|
if self.mode == "apps_script":
|
||||||
try:
|
try:
|
||||||
@@ -284,8 +289,8 @@ class ProxyServer:
|
|||||||
host, override_ip, self.fronter.sni_host)
|
host, override_ip, self.fronter.sni_host)
|
||||||
await self._do_sni_rewrite_tunnel(host, port, reader, writer,
|
await self._do_sni_rewrite_tunnel(host, port, reader, writer,
|
||||||
connect_ip=override_ip)
|
connect_ip=override_ip)
|
||||||
elif self._is_google_domain(host):
|
elif self._should_direct_connect(host):
|
||||||
log.info("Direct tunnel → %s (Google domain, skipping relay)", host)
|
log.info("Direct tunnel → %s (skipping relay)", host)
|
||||||
await self._do_direct_tunnel(host, port, reader, writer)
|
await self._do_direct_tunnel(host, port, reader, writer)
|
||||||
else:
|
else:
|
||||||
await self._do_mitm_connect(host, port, reader, writer)
|
await self._do_mitm_connect(host, port, reader, writer)
|
||||||
@@ -415,6 +420,16 @@ class ProxyServer:
|
|||||||
return True
|
return True
|
||||||
return False
|
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) ───────────────────────────────────
|
# ── Direct tunnel (no MITM) ───────────────────────────────────
|
||||||
|
|
||||||
async def _do_direct_tunnel(self, host: str, port: int,
|
async def _do_direct_tunnel(self, host: str, port: int,
|
||||||
|
|||||||
Reference in New Issue
Block a user