Skip to content

Commit

Permalink
fix: xhttp extra in v2ray links (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMohammad20000 authored Dec 2, 2024
1 parent 4708436 commit b26f6c7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
76 changes: 39 additions & 37 deletions app/subscription/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
sc_min_posts_interval_ms=inbound.get('scMinPostsIntervalMs', 30),
x_padding_bytes=inbound.get("xPaddingBytes", "100-1000"),
mode=inbound.get("mode", "auto"),
extra=inbound.get("extra", {}),
noGRPCHeader=inbound.get("noGRPCHeader", False),
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
)

elif inbound["protocol"] == "vless":
Expand Down Expand Up @@ -108,10 +108,10 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
sc_min_posts_interval_ms=inbound.get('scMinPostsIntervalMs', 30),
x_padding_bytes=inbound.get("xPaddingBytes", "100-1000"),
mode=inbound.get("mode", "auto"),
extra=inbound.get("extra", {}),
noGRPCHeader=inbound.get("noGRPCHeader", False),
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
)

elif inbound["protocol"] == "trojan":
Expand Down Expand Up @@ -140,10 +140,10 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
sc_min_posts_interval_ms=inbound.get('scMinPostsIntervalMs', 30),
x_padding_bytes=inbound.get("xPaddingBytes", "100-1000"),
mode=inbound.get("mode", "auto"),
extra=inbound.get("extra", {}),
noGRPCHeader=inbound.get("noGRPCHeader", False),
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
xmux=inbound.get("xmux", {}),
)

elif inbound["protocol"] == "shadowsocks":
Expand Down Expand Up @@ -185,10 +185,10 @@ def vmess(
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
mode: str = "auto",
extra: dict = {},
noGRPCHeader: bool = False,
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
):
payload = {
"add": address,
Expand Down Expand Up @@ -233,15 +233,18 @@ def vmess(
payload["mode"] = "gun"

elif net in ("splithttp", "xhttp"):
payload["scMaxEachPostBytes"] = sc_max_each_post_bytes
payload["scMaxConcurrentPosts"] = sc_max_concurrent_posts
payload["scMinPostsIntervalMs"] = sc_min_posts_interval_ms
payload["xPaddingBytes"] = x_padding_bytes
extra = {
"scMaxEachPostBytes": sc_max_each_post_bytes,
"scMaxConcurrentPosts": sc_max_concurrent_posts,
"scMinPostsIntervalMs": sc_min_posts_interval_ms,
"xPaddingBytes": x_padding_bytes,
"noGRPCHeader": noGRPCHeader,
"keepAlivePeriod": keepAlivePeriod,
}
if xmux:
extra["xmux"] = xmux
payload["type"] = mode
if extra:
payload["extra"] = extra
payload["noGRPCHeader"] = int(noGRPCHeader)
payload["keepAlivePeriod"] = keepAlivePeriod
payload["extra"] = extra

elif net == "ws":
if heartbeatPeriod:
Expand Down Expand Up @@ -280,10 +283,10 @@ def vless(cls,
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
mode: str = "auto",
extra: dict = {},
noGRPCHeader: bool = False,
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
):

payload = {
Expand All @@ -309,15 +312,18 @@ def vless(cls,
elif net in ("splithttp", "xhttp"):
payload["path"] = path
payload["host"] = host
payload["scMaxEachPostBytes"] = sc_max_each_post_bytes
payload["scMaxConcurrentPosts"] = sc_max_concurrent_posts
payload["scMinPostsIntervalMs"] = sc_min_posts_interval_ms
payload["xPaddingBytes"] = x_padding_bytes
payload["mode"] = mode
if extra:
payload["extra"] = json.dumps(extra)
payload["noGRPCHeader"] = int(noGRPCHeader)
payload["keepAlivePeriod"] = keepAlivePeriod
extra = {
"scMaxEachPostBytes": sc_max_each_post_bytes,
"scMaxConcurrentPosts": sc_max_concurrent_posts,
"scMinPostsIntervalMs": sc_min_posts_interval_ms,
"xPaddingBytes": x_padding_bytes,
"noGRPCHeader": noGRPCHeader,
"keepAlivePeriod": keepAlivePeriod,
}
if xmux:
extra["xmux"] = xmux
payload["extra"] = json.dumps(extra)

elif net == 'kcp':
payload['seed'] = path
Expand Down Expand Up @@ -384,10 +390,10 @@ def trojan(cls,
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
mode: str = "auto",
extra: dict = {},
noGRPCHeader: bool = False,
heartbeatPeriod: int = 0,
keepAlivePeriod: int = 0,
xmux: dict = {},
):

payload = {
Expand All @@ -409,15 +415,18 @@ def trojan(cls,
elif net in ("splithttp", "xhttp"):
payload["path"] = path
payload["host"] = host
payload["scMaxEachPostBytes"] = sc_max_each_post_bytes
payload["scMaxConcurrentPosts"] = sc_max_concurrent_posts
payload["scMinPostsIntervalMs"] = sc_min_posts_interval_ms
payload["xPaddingBytes"] = x_padding_bytes
payload["mode"] = mode
if extra:
payload["extra"] = json.dumps(extra)
payload["noGRPCHeader"] = int(noGRPCHeader)
payload["keepAlivePeriod"] = keepAlivePeriod
extra = {
"scMaxEachPostBytes": sc_max_each_post_bytes,
"scMaxConcurrentPosts": sc_max_concurrent_posts,
"scMinPostsIntervalMs": sc_min_posts_interval_ms,
"xPaddingBytes": x_padding_bytes,
"noGRPCHeader": noGRPCHeader,
"keepAlivePeriod": keepAlivePeriod,
}
if xmux:
extra["xmux"] = xmux
payload["extra"] = json.dumps(extra)

elif net == 'quic':
payload['key'] = path
Expand Down Expand Up @@ -586,7 +595,6 @@ def splithttp_config(self, path: str = "", host: str = "", random_user_agent: bo
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
xmux: dict = {},
extra: dict = {},
mode: str = "auto",
noGRPCHeader: bool = False,
keepAlivePeriod: int = 0,
Expand All @@ -608,9 +616,6 @@ def splithttp_config(self, path: str = "", host: str = "", random_user_agent: bo
config["noGRPCHeader"] = noGRPCHeader
if xmux:
config["xmux"] = xmux

if extra:
config["extra"] = extra
config["keepAlivePeriod"] = keepAlivePeriod
# core will ignore unknown variables

Expand Down Expand Up @@ -912,7 +917,6 @@ def make_stream_setting(self,
sc_min_posts_interval_ms: int = 30,
x_padding_bytes: str = "100-1000",
xmux: dict = {},
extra: dict = {},
mode: str = "auto",
noGRPCHeader: bool = False,
heartbeatPeriod: int = 0,
Expand Down Expand Up @@ -947,7 +951,6 @@ def make_stream_setting(self,
sc_min_posts_interval_ms=sc_min_posts_interval_ms,
x_padding_bytes=x_padding_bytes,
xmux=xmux,
extra=extra,
mode=mode,
noGRPCHeader=noGRPCHeader,
keepAlivePeriod=keepAlivePeriod,
Expand Down Expand Up @@ -1059,7 +1062,6 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
x_padding_bytes=inbound.get("xPaddingBytes", "100-1000"),
xmux=inbound.get("xmux", {}),
mode=inbound.get("mode", "auto"),
extra=inbound.get("extra", {}),
noGRPCHeader=inbound.get("noGRPCHeader", False),
heartbeatPeriod=inbound.get("heartbeatPeriod", 0),
keepAlivePeriod=inbound.get("keepAlivePeriod", 0),
Expand Down
1 change: 0 additions & 1 deletion app/xray/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def _resolve_inbounds(self):
settings['xPaddingBytes'] = net_settings.get('xPaddingBytes', "100-1000")
settings['xmux'] = net_settings.get('xmux', {})
settings["mode"] = net_settings.get("mode", "auto")
settings["extra"] = net_settings.get("extra", {})
settings["noGRPCHeader"] = net_settings.get("noGRPCHeader", False)
settings["keepAlivePeriod"] = net_settings.get("keepAlivePeriod", 0)

Expand Down

0 comments on commit b26f6c7

Please sign in to comment.