From 82d5ad9156cd9451c0359f02637d305ca951aad9 Mon Sep 17 00:00:00 2001 From: Arthur Degonde <44548105+ArthurD1@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:17:23 +0200 Subject: [PATCH] feat: handle content length for requests --- harp/http/requests.py | 1 + harp/http/responses.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/harp/http/requests.py b/harp/http/requests.py index a094d4c6..edd95fe2 100644 --- a/harp/http/requests.py +++ b/harp/http/requests.py @@ -108,6 +108,7 @@ async def aread(self): nothing. This method does nothing if the body has already been read.""" if not hasattr(self, "_body"): self._body = b"".join([part async for part in self._stream]) + self.headers["content-length"] = str(len(self.body)) if not isinstance(self._stream, ByteStream): self._stream = ByteStream(self._body) return self.body diff --git a/harp/http/responses.py b/harp/http/responses.py index 3454dfd3..a4a0e154 100644 --- a/harp/http/responses.py +++ b/harp/http/responses.py @@ -46,6 +46,10 @@ def status(self) -> int: def headers(self) -> CIMultiDict: return self._headers + @headers.setter + def headers(self, headers: CIMultiDict): + self._headers = CIMultiDict(headers) + @property def content_type(self) -> str: return self._headers.get("content-type", "text/plain")