Description
Long story short
I have created middleware for forwarding requests and I need to read content of them. I figure out behaviour that it is rather strange for me.
I send request (post/get) and text/read return body of message (post/json data is included). But content (StreamReader instance,) returns empty string.
And documentation says:
content
A StreamReader instance, input stream for reading request’s BODY.
Read-only property.
Expected behaviour
I suppose that content is body of message (https://docs.aiohttp.org/en/stable/web_reference.html#aiohttp.web.BaseRequest.content)
Actual behaviour
Method request.content.read() return empty string as result.
Steps to reproduce
send request:
- await test_app.post("/get_fce", data={"hello": "kitty"})
>>> print(await request.read())
b'hello=kitty'
>>> print(await request.text())
hello=kitty
>>> print(await request.content.read())
b''
- await test_app.post("/get_fce", json={"hello": "kitty"})
>>> print(await request.read())
b'{"hello": "kitty"}'
>>> print(await request.text())
{"hello": "kitty"}
>>> print(await request.content.read())
b''
Your environment
aiohttp==3.1.0
aioredis==1.1.0
async-timeout==2.0.1 # via aiohttp
attrs==17.4.0 # via aiohttp
chardet==3.0.4 # via aiohttp
idna-ssl==1.0.1 # via aiohttp
multidict==4.1.0 # via aiohttp, yarl
ujson==1.35
yarl==1.1.1
Metadata
Metadata
Assignees
Labels
Type
Projects
Status