From 9cc204b0613a677bb3fec0b7bd357eb2968144ae Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 7 Feb 2022 21:46:10 +0100 Subject: Headers are now a list of tuples --- ttun/client.py | 11 ++++------- ttun/types.py | 6 ++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/ttun/client.py b/ttun/client.py index eac40da..b4be4e7 100644 --- a/ttun/client.py +++ b/ttun/client.py @@ -1,18 +1,17 @@ import asyncio import json from base64 import b64encode, b64decode -from time import perf_counter, process_time +from time import perf_counter from typing import Optional, Callable, Coroutine, Awaitable from uuid import uuid4 import websockets -from aiohttp import ClientSession +from aiohttp import ClientSession, DummyCookieJar from websockets import WebSocketClientProtocol from websockets.exceptions import ConnectionClosed from ttun.pubsub import PubSub from ttun.types import Config, RequestData, ResponseData -from timeit import timeit class Client: @@ -69,7 +68,7 @@ class Client: break async def proxyRequest(self, request: RequestData, on_response: Callable[[ResponseData], Awaitable] = None): - async with ClientSession() as session: + async with ClientSession(cookie_jar=DummyCookieJar()) as session: request_id = uuid4() await PubSub.publish({ "type": "request", @@ -84,7 +83,6 @@ class Client: method=request['method'], url=f'http://localhost:{self.port}{request["path"]}', headers=request['headers'], - cookies=request['cookies'], data=b64decode(request['body'].encode()), allow_redirects=False ) @@ -92,8 +90,7 @@ class Client: response_data = ResponseData( status=response.status, - headers=dict(response.headers), - cookies=dict(response.cookies), + headers=list(response.headers.items()), body=b64encode(await response.read()).decode() ) diff --git a/ttun/types.py b/ttun/types.py index cf94b9e..640ac5d 100644 --- a/ttun/types.py +++ b/ttun/types.py @@ -8,15 +8,13 @@ class Message(TypedDict): class RequestData(TypedDict): method: str path: str - headers: dict - cookies: dict + headers: list[tuple[str, str]] body: Optional[str] class ResponseData(TypedDict): status: int - headers: dict - cookies: dict + headers: list[tuple[str, str]] body: Optional[str] -- cgit v1.2.3