diff --git a/pyproject.toml b/pyproject.toml index 064caeb..bb69bc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ requires-python = ">=3.13" dependencies = [ "megasniff>=0.2.0", "breakshaft>=0.1.0", + "case-insensitive-dictionary>=0.2.1", ] [tool.uv.sources] diff --git a/src/turbosloth/types.py b/src/turbosloth/types.py index b4e16a2..cc014fb 100644 --- a/src/turbosloth/types.py +++ b/src/turbosloth/types.py @@ -6,6 +6,8 @@ from typing import Callable, Awaitable, Dict, Literal, Any, TypeVar import urllib.parse +from case_insensitive_dict.case_insensitive_dict import CaseInsensitiveDict + type Scope = Dict type Receive = Callable[[], Awaitable[Dict]] type Send = Callable[[Dict], Awaitable[None]] @@ -31,7 +33,7 @@ V = TypeVar('V') class BasicRequest: method: str path: str - headers: dict[str, str] + headers: CaseInsensitiveDict[str, str] query: dict[str, list[str] | str] body: dict[str, Any] @@ -39,7 +41,7 @@ class BasicRequest: def from_scope(cls, scope: Scope) -> BasicRequest: path = scope['path'] method = scope['method'] - headers = {} + headers = CaseInsensitiveDict() for key, value in scope.get('headers', []): headers[key.decode('latin1')] = value.decode('latin1') @@ -60,7 +62,7 @@ class BasicRequest: @dataclass class BasicResponse: code: int - headers: dict[str, str] + headers: CaseInsensitiveDict[str, str] body: bytes def into_start_message(self) -> dict: diff --git a/uv.lock b/uv.lock index 88f079b..6097818 100644 --- a/uv.lock +++ b/uv.lock @@ -15,6 +15,15 @@ wheels = [ { url = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/files/breakshaft/0.1.0/breakshaft-0.1.0-py3-none-any.whl", hash = "sha256:e7c8831e5889fbcd788d59fee05f7aee113663ebef9273cd280893e1ed04f5c2" }, ] +[[package]] +name = "case-insensitive-dictionary" +version = "0.2.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/5e/8de464e77e2bb6f0b47f2ac94f75cd46f4f14ba55529619e68ae5e81443e/case-insensitive-dictionary-0.2.1.tar.gz", hash = "sha256:7e94726f97eb2c0ceac53209971db50ffc996def663e5e5080d0a1acb4a42280", size = 5938, upload-time = "2022-10-18T10:35:30.298Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9e/94/2a5f43133bfd07d8c826f5fe277d54fb6c45c0c2ac5df3bc71c2ba8ff4ea/case_insensitive_dictionary-0.2.1-py3-none-any.whl", hash = "sha256:a8971780be1ba25e363db259515f0a2f003013465f82552e2f9aed08d5a9ca28", size = 6060, upload-time = "2022-10-18T10:35:31.701Z" }, +] + [[package]] name = "click" version = "8.2.1" @@ -234,6 +243,7 @@ version = "0.1.0" source = { editable = "." } dependencies = [ { name = "breakshaft" }, + { name = "case-insensitive-dictionary" }, { name = "megasniff" }, ] @@ -247,6 +257,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "breakshaft", specifier = ">=0.1.0", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" }, + { name = "case-insensitive-dictionary", specifier = ">=0.2.1" }, { name = "megasniff", specifier = ">=0.2.0", index = "https://git.nikto-b.ru/api/packages/nikto_b/pypi/simple" }, ]