Skip to content

Commit

Permalink
feat: handle content length for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurD1 committed Jul 29, 2024
1 parent e72a045 commit 82d5ad9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions harp/http/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions harp/http/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 82d5ad9

Please sign in to comment.