Repository navigation
Cannot correctly set content length after modify the request content #3303
Replies: 1 comment
|
The length calculation is for the new bytes, but After producing your encrypted envelope, construct a replacement request through the public API: # Inside handle_async_request, after reading/encrypting the original body:
data = {"token": token, "data": encrypted_data}
headers = request.headers.copy()
headers.pop("content-length", None)
headers.pop("transfer-encoding", None)
outgoing = httpx.Request(
method=request.method,
url=request.url,
headers=headers,
json=data,
extensions=request.extensions,
)
response = await self._wrapper.handle_async_request(outgoing)Removing the old framing headers lets HTTPX generate a length matching the newly serialized JSON. Keeping I checked this on HTTPX 0.28.1: changing only Also forward cleanup to the wrapped transport: async def aclose(self):
await self._wrapper.aclose()See |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I need an interceptor to implement the req/rep encryption. For the decrypt part, I've managed it worked, but encryption still struggling.
All the requests and responses are in JSON format, but maybe with
datafield encryted (depending on the header).If I modify the content of the request in this transport, the system would throw
LocalProtocolError: Too little data for declared Content-Length, how to deal with it?All reactions