fix: xhttp-reality parsing
This commit is contained in:
2 files changed
+38
-8
No files matched your search
@@ -43,6 +43,8 @@ def _xray_tls(tls: dict | None) -> tuple[str, dict]:
|
|||||||
"shortId": reality.get("short_id", ""),
|
"shortId": reality.get("short_id", ""),
|
||||||
}
|
}
|
||||||
utls = tls.get("utls", {})
|
utls = tls.get("utls", {})
|
||||||
|
if reality.get("spider_x"):
|
||||||
|
settings["spiderX"] = reality["spider_x"]
|
||||||
if utls.get("enabled") and utls.get("fingerprint"):
|
if utls.get("enabled") and utls.get("fingerprint"):
|
||||||
settings["fingerprint"] = utls["fingerprint"]
|
settings["fingerprint"] = utls["fingerprint"]
|
||||||
return "reality", {"realitySettings": settings}
|
return "reality", {"realitySettings": settings}
|
||||||
@@ -81,12 +83,14 @@ def _xray_transport(transport: dict | None) -> tuple[str, dict]:
|
|||||||
if t == "quic":
|
if t == "quic":
|
||||||
return "quic", {}
|
return "quic", {}
|
||||||
if t == "xhttp":
|
if t == "xhttp":
|
||||||
return "xhttp", {
|
settings = {"path": transport.get("path", "/")}
|
||||||
"xhttpSettings": {
|
if transport.get("host"):
|
||||||
"host": transport.get("host", ""),
|
settings["host"] = transport["host"]
|
||||||
"path": transport.get("path", "/"),
|
if transport.get("mode"):
|
||||||
}
|
settings["mode"] = transport["mode"]
|
||||||
}
|
if transport.get("extra") is not None:
|
||||||
|
settings["extra"] = transport["extra"]
|
||||||
|
return "xhttp", {"xhttpSettings": settings}
|
||||||
return t, {}
|
return t, {}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,24 @@ def _parse_url_parts(url: str, scheme: str) -> tuple[str, str, str, dict]:
|
|||||||
return userinfo, host, port, _qs(query)
|
return userinfo, host, port, _qs(query)
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_json_param(value: str, name: str) -> dict:
|
||||||
|
try:
|
||||||
|
parsed = json.loads(value)
|
||||||
|
except json.JSONDecodeError as exc:
|
||||||
|
raise ValueError(f"invalid {name} JSON: {exc}") from exc
|
||||||
|
if not isinstance(parsed, dict):
|
||||||
|
raise ValueError(f"invalid {name} JSON: expected object")
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
def _mk_transport(
|
def _mk_transport(
|
||||||
transport_type: str,
|
transport_type: str,
|
||||||
path: str = "/",
|
path: str = "/",
|
||||||
host_header: str = "",
|
host_header: str = "",
|
||||||
service_name: str = "",
|
service_name: str = "",
|
||||||
|
mode: str = "",
|
||||||
|
extra: str = "",
|
||||||
|
x_padding_bytes: str = "",
|
||||||
) -> "dict | None":
|
) -> "dict | None":
|
||||||
normalized = transport_type.lower()
|
normalized = transport_type.lower()
|
||||||
|
|
||||||
@@ -85,11 +98,19 @@ def _mk_transport(
|
|||||||
"type": "quic",
|
"type": "quic",
|
||||||
}
|
}
|
||||||
if normalized in ("xhttp", "splithttp"):
|
if normalized in ("xhttp", "splithttp"):
|
||||||
return {
|
transport = {
|
||||||
"type": "xhttp",
|
"type": "xhttp",
|
||||||
"host": host_header,
|
|
||||||
"path": urllib.parse.unquote(path),
|
"path": urllib.parse.unquote(path),
|
||||||
}
|
}
|
||||||
|
if host_header:
|
||||||
|
transport["host"] = host_header
|
||||||
|
if mode:
|
||||||
|
transport["mode"] = mode
|
||||||
|
if extra:
|
||||||
|
transport["extra"] = _parse_json_param(extra, "xhttp extra")
|
||||||
|
elif x_padding_bytes:
|
||||||
|
transport["extra"] = {"xPaddingBytes": x_padding_bytes}
|
||||||
|
return transport
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -148,6 +169,8 @@ def parse_vless(url: str, tag: str, backend: str = "sing-box") -> dict:
|
|||||||
"public_key": params["pbk"],
|
"public_key": params["pbk"],
|
||||||
"short_id": params.get("sid", ""),
|
"short_id": params.get("sid", ""),
|
||||||
}
|
}
|
||||||
|
if params.get("spx"):
|
||||||
|
ob["tls"]["reality"]["spider_x"] = params["spx"]
|
||||||
elif security == "tls":
|
elif security == "tls":
|
||||||
ob["tls"] = _mk_tls(
|
ob["tls"] = _mk_tls(
|
||||||
params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn")
|
params.get("sni", host), fp=params.get("fp"), alpn=params.get("alpn")
|
||||||
@@ -160,6 +183,9 @@ def parse_vless(url: str, tag: str, backend: str = "sing-box") -> dict:
|
|||||||
path=params.get("path", "/"),
|
path=params.get("path", "/"),
|
||||||
host_header=params.get("host", host),
|
host_header=params.get("host", host),
|
||||||
service_name=params.get("serviceName", ""),
|
service_name=params.get("serviceName", ""),
|
||||||
|
mode=params.get("mode", ""),
|
||||||
|
extra=params.get("extra", ""),
|
||||||
|
x_padding_bytes=params.get("x_padding_bytes", ""),
|
||||||
)
|
)
|
||||||
if tr is not None:
|
if tr is not None:
|
||||||
ob["transport"] = tr
|
ob["transport"] = tr
|
||||||
|
|||||||
Reference in new issue
Block a user