BaseRequest.body_exists returns wrong value on (at least) GET #4528
Description
Long story short
This is related to #2005.
In my tests using pytest-aiohttp, aiohttp.web.BaseRequest.body_exists returns True on a GET request, which shoul have no body.
So either the client code acts strangely on the testing side, or the server interprets differently an empty body based on to the HTTP method of the request.
The tests inside aiohttp for #2005 have only been implemented with the POST method, with and without data, but not with the GET method. See tests in tests/test_web_functional.py:test_empty_content_for_query_without_body
If you change the route.add_post by route.add_get in that test, I suspect it will break.
The feature was implemented this way:
https://github.com/aio-libs/aiohttp/blob/v3.6.2/aiohttp/web_request.py#L540
@reify
def body_exists(self) -> bool:
"""Return True if request has HTTP BODY, False otherwise."""
return type(self._payload) is not EmptyStreamReaderIn my case, for DELETE I see an EmptyStreamReader, but for a GET, I see a normal StreamReader with 0 bytes in it. As it is the type that is tested, the value returned is wrong.
Expected behaviour
aiohttp.web.BaseRequest.body_exists should return True when there's a body, and False when there's no body, independently of the HTTP method used.
Actual behaviour
aiohttp.web.BaseRequest.body_exists returns True for a GET (wrong: False expected)
aiohttp.web.BaseRequest.body_exists returns False for a DELETE (ok: False expected)
Might be worth testing other HTTP methods too.
Steps to reproduce
See tests above.
Your environment
Ubuntu 18.04.3
aiohttp 3.6.2, both client and server