diff options
| author | 2026-09-04 17:09:24 +0200 | |
|---|---|---|
| committer | 2026-09-04 17:09:24 +0200 | |
| commit | 6b6f20a032eb31d747366c8bc270ca81731eaf6a (patch) | |
| tree | ada48080495267bebde4ee1251bbbe77d629745f /proxy/endpoints.py | |
| parent | 2d22158dd95f76399f5716d556be60c77da04a46 (diff) | |
| download | server-6b6f20a032eb31d747366c8bc270ca81731eaf6a.tar.gz server-6b6f20a032eb31d747366c8bc270ca81731eaf6a.tar.bz2 server-6b6f20a032eb31d747366c8bc270ca81731eaf6a.zip | |
Fixed pre-commit issuesv3
Diffstat (limited to 'proxy/endpoints.py')
| -rw-r--r-- | proxy/endpoints.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/proxy/endpoints.py b/proxy/endpoints.py index 0a23e7b..f514226 100644 --- a/proxy/endpoints.py +++ b/proxy/endpoints.py | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | import logging | 1 | import logging |
| 2 | from base64 import b64encode, b64decode | 2 | from base64 import b64decode, b64encode |
| 3 | from uuid import uuid4 | 3 | from uuid import uuid4 |
| 4 | 4 | ||
| 5 | from starlette.endpoints import HTTPEndpoint | 5 | from starlette.endpoints import HTTPEndpoint |
| 6 | from starlette.requests import Request | 6 | from starlette.requests import Request |
| 7 | from starlette.responses import Response | 7 | from starlette.responses import Response |
| 8 | 8 | ||
| 9 | from proxy.utils import get_path_with_query_string | ||
| 10 | from proxy.queue import ProxyQueue | 9 | from proxy.queue import ProxyQueue |
| 10 | from proxy.utils import get_path_with_query_string | ||
| 11 | from ttun_server.types import HttpMessage, HttpMessageType, HttpRequestData | 11 | from ttun_server.types import HttpMessage, HttpMessageType, HttpRequestData |
| 12 | 12 | ||
| 13 | logger = logging.getLogger(__name__) | 13 | logger = logging.getLogger(__name__) |
| @@ -18,16 +18,15 @@ class HeaderMapping: | |||
| 18 | self._headers = headers | 18 | self._headers = headers |
| 19 | 19 | ||
| 20 | def items(self): | 20 | def items(self): |
| 21 | for header in self._headers: | 21 | yield from self._headers |
| 22 | yield header | ||
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | class Proxy(HTTPEndpoint): | 24 | class Proxy(HTTPEndpoint): |
| 26 | async def dispatch(self) -> None: | 25 | async def dispatch(self) -> None: |
| 27 | request = Request(self.scope, self.receive) | 26 | request = Request(self.scope, self.receive) |
| 28 | 27 | ||
| 29 | subdomain = request.path_params['subdomain'] | 28 | subdomain = request.path_params["subdomain"] |
| 30 | response = Response(content='Not Found', status_code=404) | 29 | response = Response(content="Not Found", status_code=404) |
| 31 | 30 | ||
| 32 | identifier = str(uuid4()) | 31 | identifier = str(uuid4()) |
| 33 | response_queue = await ProxyQueue.create_for_identifier(identifier) | 32 | response_queue = await ProxyQueue.create_for_identifier(identifier) |
| @@ -35,7 +34,7 @@ class Proxy(HTTPEndpoint): | |||
| 35 | try: | 34 | try: |
| 36 | request_queue = await ProxyQueue.get_for_identifier(subdomain) | 35 | request_queue = await ProxyQueue.get_for_identifier(subdomain) |
| 37 | 36 | ||
| 38 | logger.debug('PROXY %s%s ', subdomain, request.url) | 37 | logger.debug("PROXY %s%s ", subdomain, request.url) |
| 39 | await request_queue.enqueue( | 38 | await request_queue.enqueue( |
| 40 | HttpMessage( | 39 | HttpMessage( |
| 41 | type=HttpMessageType.request.value, | 40 | type=HttpMessageType.request.value, |
| @@ -44,17 +43,17 @@ class Proxy(HTTPEndpoint): | |||
| 44 | method=request.method, | 43 | method=request.method, |
| 45 | path=get_path_with_query_string(request), | 44 | path=get_path_with_query_string(request), |
| 46 | headers=list(request.headers.items()), | 45 | headers=list(request.headers.items()), |
| 47 | body=b64encode(await request.body()).decode() | 46 | body=b64encode(await request.body()).decode(), |
| 48 | ) | 47 | ), |
| 49 | ) | 48 | ) |
| 50 | ) | 49 | ) |
| 51 | 50 | ||
| 52 | _response = await response_queue.dequeue() | 51 | _response = await response_queue.dequeue() |
| 53 | payload = _response['payload'] | 52 | payload = _response["payload"] |
| 54 | response = Response( | 53 | response = Response( |
| 55 | status_code=payload['status'], | 54 | status_code=payload["status"], |
| 56 | headers=HeaderMapping(payload['headers']), | 55 | headers=HeaderMapping(payload["headers"]), |
| 57 | content=b64decode(payload['body'].encode()) | 56 | content=b64decode(payload["body"].encode()), |
| 58 | ) | 57 | ) |
| 59 | except AssertionError: | 58 | except AssertionError: |
| 60 | pass | 59 | pass |
