Skip to content

Commit

Permalink
feat(xray): add headers support to ws, httpupgrade and h2
Browse files Browse the repository at this point in the history
  • Loading branch information
khodedawsh committed Jun 4, 2024
1 parent a6d5d29 commit ac6093d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions v2share/data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import base64
import json
import urllib.parse as urlparse
from dataclasses import dataclass
from typing import Optional
from dataclasses import dataclass, field
from typing import Optional, Dict
from uuid import UUID

from v2share._utils import filter_dict
Expand All @@ -19,6 +19,7 @@ class V2Data:
vmess_security: str = "auto"
password: Optional[str] = None
host: Optional[str] = None
http_headers: Dict[str, str] = field(default_factory=dict)
transport_type: str = "tcp"
grpc_multi_mode: bool = False
path: Optional[str] = None
Expand Down
31 changes: 20 additions & 11 deletions v2share/xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def reality_config(public_key, short_id, sni, fingerprint="", spiderx=""):
return realitySettings

@staticmethod
def ws_config(path=None, host=None):
def ws_config(path=None, host=None, headers=None):
if headers is None:
headers = {}

ws_settings = {}
ws_settings = {"headers": headers}
if path:
ws_settings["path"] = path
if host:
Expand All @@ -123,9 +125,11 @@ def ws_config(path=None, host=None):
return ws_settings

@staticmethod
def httpupgrade_config(path=None, host=None):
def httpupgrade_config(path=None, host=None, headers=None):
if headers is None:
headers = {}

httpupgrade_settings = {}
httpupgrade_settings = {"headers": headers}
if path:
httpupgrade_settings["path"] = path
if host:
Expand Down Expand Up @@ -161,16 +165,17 @@ def tcp_http_config(header_type=None):
return tcp_settings

@staticmethod
def h2_config(path=None, host=None):
def h2_config(path=None, host=None, headers=None):
if host is None:
host = []
if path is None:
path = "/"
http_settings = {"path": path}
if host:
http_settings["host"] = host
else:
http_settings["host"] = []
if headers is None:
headers = {}

http_settings = {"path": path, "host": host}
if headers:
http_settings["headers"] = headers

return http_settings

Expand Down Expand Up @@ -223,7 +228,11 @@ def make_stream_settings(
header_type=None,
grpc_multi_mode=False,
dialer_proxy=None,
headers=None,
):
if headers is None:
headers = {}

stream_settings = {"network": net}

if net == "ws":
Expand All @@ -234,7 +243,7 @@ def make_stream_settings(
)
elif net == "h2":
stream_settings["httpSettings"] = XrayConfig.h2_config(
path=path, host=[host]
path=path, host=[host], headers=headers
)
elif net == "kcp":
stream_settings["kcpSettings"] = XrayConfig.kcp_config(
Expand Down

0 comments on commit ac6093d

Please sign in to comment.