diff options
| author | 2022-12-19 14:29:32 +0100 | |
|---|---|---|
| committer | 2022-12-19 14:29:32 +0100 | |
| commit | 5de658f155c3af12b28aee51bcbd4a7dc754ea77 (patch) | |
| tree | f924fb96e928b34f392af9c7427cfb79d8691ad2 | |
| parent | 2e8654687b48ec912ac603ce313c63867e973549 (diff) | |
| download | client-1.6.0.tar.gz client-1.6.0.tar.bz2 client-1.6.0.zip | |
Pass headers to the serverv1.6.0
| -rw-r--r-- | ttun/__main__.py | 4 | ||||
| -rw-r--r-- | ttun/client.py | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/ttun/__main__.py b/ttun/__main__.py index 49d8b07..b14d0e7 100644 --- a/ttun/__main__.py +++ b/ttun/__main__.py | |||
| @@ -21,7 +21,8 @@ header_regex = re.compile("(?P<header>\w+)") | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | def header(v) -> Tuple[str, str]: | 23 | def header(v) -> Tuple[str, str]: |
| 24 | return v | 24 | name, *value = v.split(":") |
| 25 | return name.strip(), ":".join(value).strip() | ||
| 25 | 26 | ||
| 26 | 27 | ||
| 27 | def main(): | 28 | def main(): |
| @@ -67,6 +68,7 @@ def main(): | |||
| 67 | server=args.server, | 68 | server=args.server, |
| 68 | to=args.to, | 69 | to=args.to, |
| 69 | https=args.https, | 70 | https=args.https, |
| 71 | headers=args.header, | ||
| 70 | ) | 72 | ) |
| 71 | 73 | ||
| 72 | try: | 74 | try: |
diff --git a/ttun/client.py b/ttun/client.py index 5434f0e..1218283 100644 --- a/ttun/client.py +++ b/ttun/client.py | |||
| @@ -7,7 +7,9 @@ from time import perf_counter | |||
| 7 | from typing import Awaitable | 7 | from typing import Awaitable |
| 8 | from typing import Callable | 8 | from typing import Callable |
| 9 | from typing import Coroutine | 9 | from typing import Coroutine |
| 10 | from typing import List | ||
| 10 | from typing import Optional | 11 | from typing import Optional |
| 12 | from typing import Tuple | ||
| 11 | from uuid import uuid4 | 13 | from uuid import uuid4 |
| 12 | 14 | ||
| 13 | import websockets | 15 | import websockets |
| @@ -32,6 +34,7 @@ class Client: | |||
| 32 | subdomain: str = None, | 34 | subdomain: str = None, |
| 33 | to: str = "127.0.0.1", | 35 | to: str = "127.0.0.1", |
| 34 | https: bool = False, | 36 | https: bool = False, |
| 37 | headers: List[Tuple[str, str]] = None, | ||
| 35 | ): | 38 | ): |
| 36 | self.server = server | 39 | self.server = server |
| 37 | self.subdomain = subdomain | 40 | self.subdomain = subdomain |
| @@ -41,6 +44,8 @@ class Client: | |||
| 41 | 44 | ||
| 42 | self.proxy_origin = f'{"https" if https else "http"}://{to}:{port}' | 45 | self.proxy_origin = f'{"https" if https else "http"}://{to}:{port}' |
| 43 | 46 | ||
| 47 | self.headers = [] if headers is None else headers | ||
| 48 | |||
| 44 | async def send(self, data: dict): | 49 | async def send(self, data: dict): |
| 45 | await self.connection.send(json.dumps(data)) | 50 | await self.connection.send(json.dumps(data)) |
| 46 | 51 | ||
| @@ -80,6 +85,11 @@ class Client: | |||
| 80 | while True: | 85 | while True: |
| 81 | try: | 86 | try: |
| 82 | request: RequestData = await self.receive() | 87 | request: RequestData = await self.receive() |
| 88 | |||
| 89 | request["headers"] = [ | ||
| 90 | *request["headers"], | ||
| 91 | *self.headers, | ||
| 92 | ] | ||
| 83 | await self.proxy_request( | 93 | await self.proxy_request( |
| 84 | session=session, | 94 | session=session, |
| 85 | request=request, | 95 | request=request, |
