From 0fc249d60fd3903d4d582649a35b83ea72ac5de9 Mon Sep 17 00:00:00 2001 From: Dawsh Date: Tue, 4 Jun 2024 17:08:06 +0330 Subject: [PATCH] feat(xray): add headers support to http, ws and httpupgrade --- v2share/singbox.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/v2share/singbox.py b/v2share/singbox.py index 84e6cfc..da2da22 100644 --- a/v2share/singbox.py +++ b/v2share/singbox.py @@ -74,10 +74,15 @@ 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: @@ -85,6 +90,7 @@ def transport_config( 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=") @@ -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 @@ -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"):