Skip to content

Commit

Permalink
feat(xray): add headers support to http, ws and httpupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
khodedawsh committed Jun 4, 2024
1 parent ac6093d commit 0fc249d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions v2share/singbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,23 @@ def transport_config(
host=None,
path=None,
http_method=None,
headers=None,
):
if headers is None:
headers = {}

transport_config = {"type": transport_type}

if transport_type == "http":
transport_config["headers"] = headers
if host:
transport_config["host"] = host
if path:
transport_config["path"] = path
if http_method:
transport_config["method"] = http_method
elif transport_type == "ws":
transport_config["headers"] = headers
if path:
if "?ed=" in path:
path, max_early_data = path.split("?ed=")
Expand All @@ -95,16 +101,16 @@ def transport_config(
transport_config["max_early_data"] = max_early_data
transport_config["path"] = path
if host:
transport_config["headers"] = {"Host": host}
elif transport_type == "grpc":
if path:
transport_config["service_name"] = path

transport_config["headers"]["Host"] = host
elif transport_type == "httpupgrade":
transport_config["headers"] = headers
if host:
transport_config["host"] = host
if path:
transport_config["path"] = path
elif transport_type == "grpc":
if path:
transport_config["service_name"] = path

return transport_config

Expand All @@ -128,6 +134,7 @@ def add_proxies(self, proxies: List[V2Data]):
transport_type=data.transport_type,
host=data.host,
path=data.path,
headers=data.http_headers,
)

if data.tls in ("tls", "reality"):
Expand Down

0 comments on commit 0fc249d

Please sign in to comment.