add direct_domains
This commit is contained in:
+17
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user