Skip to content

Commit

Permalink
fix(subscription): use deepcopy to avoid conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
M03ED committed Aug 4, 2024
1 parent cb7aa7a commit f7d20b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
15 changes: 8 additions & 7 deletions app/subscription/singbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import copy
from random import choice

from jinja2.exceptions import TemplateNotFound
Expand Down Expand Up @@ -95,12 +96,12 @@ def tls_config(sni=None, fp=None, tls=None, pbk=None,
return config

def http_config(self, host='', path='', random_user_agent: bool = False):
config = self.settings.get("httpSettings", {
config = copy.deepcopy(self.settings.get("httpSettings", {
"idle_timeout": "15s",
"ping_timeout": "15s",
"method": "GET",
"headers": {}
})
}))
if "headers" not in config:
config["headers"] = {}

Expand All @@ -116,9 +117,9 @@ def http_config(self, host='', path='', random_user_agent: bool = False):

def ws_config(self, host='', path='', random_user_agent: bool = False,
max_early_data=None, early_data_header_name=None):
config = self.settings.get("wsSettings", {
config = copy.deepcopy(self.settings.get("wsSettings", {
"headers": {}
})
}))
if "headers" not in config:
config["headers"] = {}

Expand All @@ -136,17 +137,17 @@ def ws_config(self, host='', path='', random_user_agent: bool = False,
return config

def grpc_config(self, path=''):
config = self.settings.get("grpcSettings", {})
config = copy.deepcopy(self.settings.get("grpcSettings", {}))

if path:
config["service_name"] = path

return config

def httpupgrade_config(self, host='', path='', random_user_agent: bool = False):
config = self.settings.get("httpupgradeSettings", {
config = copy.deepcopy(self.settings.get("httpupgradeSettings", {
"headers": {}
})
}))
if "headers" not in config:
config["headers"] = {}

Expand Down
31 changes: 16 additions & 15 deletions app/subscription/v2ray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
import copy
import urllib.parse as urlparse
from random import choice
from typing import Union
Expand Down Expand Up @@ -486,7 +487,7 @@ def reality_config(sni=None, fp=None, pbk=None, sid=None, spx=None):
return realitySettings

def ws_config(self, path=None, host=None, random_user_agent=None):
wsSettings = self.settings.get("wsSettings", {})
wsSettings = copy.deepcopy(self.settings.get("wsSettings", {}))

if "headers" not in wsSettings:
wsSettings["headers"] = {}
Expand All @@ -500,7 +501,7 @@ def ws_config(self, path=None, host=None, random_user_agent=None):
return wsSettings

def httpupgrade_config(self, path=None, host=None, random_user_agent=None):
httpupgradeSettings = self.settings.get("httpupgradeSettings", {})
httpupgradeSettings = copy.deepcopy(self.settings.get("httpupgradeSettings", {}))

if "headers" not in httpupgradeSettings:
httpupgradeSettings["headers"] = {}
Expand All @@ -519,7 +520,7 @@ def splithttp_config(self, path=None, host=None, random_user_agent=None,
sc_max_concurrent_posts: int = 100,
sc_min_posts_interval_ms: int = 30,
):
config = self.settings.get("splithttpSettings", {})
config = copy.deepcopy(self.settings.get("splithttpSettings", {}))

if path:
config["path"] = path
Expand All @@ -541,12 +542,12 @@ def splithttp_config(self, path=None, host=None, random_user_agent=None,
return config

def grpc_config(self, path=None, host=None, multiMode=False, random_user_agent=None):
config = self.settings.get("grpcSettings", {
config = copy.deepcopy(self.settings.get("grpcSettings", {
"idle_timeout": 60,
"health_check_timeout": 20,
"permit_without_stream": False,
"initial_windows_size": 35538
})
}))

config["multiMode"] = multiMode

Expand All @@ -562,13 +563,13 @@ def grpc_config(self, path=None, host=None, multiMode=False, random_user_agent=N

def tcp_config(self, headers="none", path=None, host=None, random_user_agent=None):
if headers == "http":
config = self.settings.get("tcphttpSettings", {
config = copy.deepcopy(self.settings.get("tcphttpSettings", {
"header": {}
})
}))
else:
config = self.settings.get("tcpSettings", {
config = copy.deepcopy(self.settings.get("tcpSettings", {
"header": {}
})
}))
if "header" not in config:
config["header"] = {}

Expand Down Expand Up @@ -596,9 +597,9 @@ def tcp_config(self, headers="none", path=None, host=None, random_user_agent=Non

def http_config(self, net="http", path=None, host=None, random_user_agent=None):
if net == "h2":
config = self.settings.get("h2Settings", {
config = copy.deepcopy(self.settings.get("h2Settings", {
"header": {}
})
}))
else:
config = self.settings.get("httpSettings", {
"header": {}
Expand All @@ -621,13 +622,13 @@ def http_config(self, net="http", path=None, host=None, random_user_agent=None):
return config

def quic_config(self, path=None, host=None, header=None):
quicSettings = self.settings.get("quicSettings", {
quicSettings = copy.deepcopy(self.settings.get("quicSettings", {
"security": "none",
"header": {
"type": "none"
},
"key": ""
})
}))
if "header" not in quicSettings:
quicSettings["header"] = {"type": "none"}

Expand All @@ -641,7 +642,7 @@ def quic_config(self, path=None, host=None, header=None):
return quicSettings

def kcp_config(self, seed=None, host=None, header=None):
kcpSettings = self.settings.get("kcpSettings", {
kcpSettings = copy.deepcopy(self.settings.get("kcpSettings", {
"header": {
"type": "none"
},
Expand All @@ -652,7 +653,7 @@ def kcp_config(self, seed=None, host=None, header=None):
"congestion": False,
"readBufferSize": 2,
"writeBufferSize": 2,
})
}))
if "header" not in kcpSettings:
kcpSettings["header"] = {"type": "none"}

Expand Down

0 comments on commit f7d20b6

Please sign in to comment.