BOM发料对比

This commit is contained in:
hjq
2026-06-23 14:42:39 +08:00
parent 182cb6756f
commit d2c80682a7

View File

@@ -54,28 +54,33 @@ def patch_drission_ws_handshake() -> None:
def resilient_create_connection(address, **kwargs): def resilient_create_connection(address, **kwargs):
base_kwargs = dict(kwargs) base_kwargs = dict(kwargs)
no_proxy_hosts = ["127.0.0.1", "localhost", "::1"] no_proxy_hosts = ["127.0.0.1", "localhost", "::1"]
# Chrome DevTools 会进行 Host 校验防 DNS Rebinding我们强行补上 Host 和 Origin
candidate_kwargs = [ candidate_kwargs = [
{**base_kwargs, "http_no_proxy": no_proxy_hosts},
{**base_kwargs, "http_no_proxy": no_proxy_hosts, "suppress_origin": False},
{**{k: v for k, v in base_kwargs.items() if k != "suppress_origin"}, "http_no_proxy": no_proxy_hosts},
{ {
**{k: v for k, v in base_kwargs.items() if k != "suppress_origin"}, **base_kwargs,
"http_no_proxy": no_proxy_hosts, "http_no_proxy": no_proxy_hosts,
"origin": "http://127.0.0.1", "header": ["Host: 127.0.0.1", "Origin: http://127.0.0.1"]
}, },
{
**base_kwargs,
"http_no_proxy": no_proxy_hosts,
"suppress_origin": False,
"header": ["Host: localhost"]
},
{**base_kwargs, "http_no_proxy": no_proxy_hosts},
] ]
last_err = None last_err = None
for candidate in candidate_kwargs: for candidate in candidate_kwargs:
try: try:
return raw_ws_create_connection( return raw_ws_create_connection(
address, address.replace("127.0.0.1", "localhost"), # 部分 Chrome 只认 localhost
http_proxy_host=None, http_proxy_host=None,
http_proxy_port=None, http_proxy_port=None,
**candidate, **candidate,
) )
except WebSocketBadStatusException as ws_err: except WebSocketBadStatusException as ws_err:
last_err = ws_err last_err = ws_err
if "Handshake status 404 Not Found" not in str(ws_err): if "Handshake status 404" not in str(ws_err) and "Handshake status 403" not in str(ws_err):
raise raise
except Exception as other_err: except Exception as other_err:
last_err = other_err last_err = other_err