-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Differences in transfer encoding handling between the C and Python HTTP parsers #4436
Comments
That's sad. |
I can do that for the Python implementation, but it'd arguably be more important to fix the C parser since that's what's presumably used most of the time. The C parser issue mentioned above has been reported upstream 3.5 years ago, and a patch is not in sight. I'm not sure if it can be fixed/worked around entirely in the Cython wrapper. |
Looking at this, the problem description is not quite correct and actually the C parser is working correctly (maybe it didn't at the time, but the output still matches).
The test here only looks at the client side, so the first paragraph is relevant here (and we'll need another test for the server side). So, the test uses In both cases the Python parser gives a |
OK, created the tests. The C parser is correct in all 4 cases, Python parser is wrong in 3 of 4. |
Long story short
The C and Python parsers in aiohttp do not handle transfer encoding the same way, and neither behaves correctly. The C parser simply discards any value that isn't
chunked
and therefore doesn't handle things likegzip, chunked
(see #4435). The Python parser accepts any value that containschunked
, including invalid values likenotchunked
, and parses (or attempts to parse) the payload as a chunked response.Expected behaviour
The C and Python implementations behave the same and according to the HTTP specification, i.e. presumably throw an error on TE values they do not support or that are invalid (though the standard does not explicitly mention that as far as I can see).
Actual behaviour
The two implementations differ and do not conform to the standard.
Steps to reproduce
A simple server and client illustrating this issue can be found in this gist. I wrote a single test client and server for both this issue and #4435; only the first line is relevant to this issue, and the others are not included in the output below.
Behaviour of the C parser:
Behaviour of the Python parser:
Your environment
I tested this with aiohttp 2.3.10 and Python 3.6.9 on Debian, but based on the current aiohttp code, the behaviour should still be the same on the current versions.
The text was updated successfully, but these errors were encountered: