-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix deflate compression (#4506) #4511
Conversation
I'm not sure I've done it right. Websockets must use deflate without headers according to RFC. I did not find anything about multipart....so I did not fix it. |
118a5a3
to
5ccb7a4
Compare
Codecov Report
@@ Coverage Diff @@
## master #4511 +/- ##
=========================================
Coverage ? 97.54%
=========================================
Files ? 43
Lines ? 8906
Branches ? 1404
=========================================
Hits ? 8687
Misses ? 98
Partials ? 121
Continue to review full report at Codecov.
|
f99c91b
to
06a94d1
Compare
Please update against the master. |
f5f6895
to
f7b7746
Compare
aiohttp/http_parser.py
Outdated
# RFC1950 | ||
# bits 0..3 = CM = 0b1000 = 8 = "deflate" | ||
# bits 4..7 = CINFO = 1..7 = windows size. | ||
if not self._started_decoding and self.encoding == 'deflate' and chunk[0] & 0xf != 8: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on very small chunks it's not enough to trigger error in the first call to decompressor. I wrote the test on it.
So, I changed the code to check the first byte of the first chunk.
|
||
if chunk: | ||
self._started_decoding = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug. this value must be set as soon as we passed something to a decoder. Small data passed as a compressed chunk might not yeld decompressed chunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
a558dd9
to
d80be17
Compare
I'm unable to fix it. It seems I tried everything. @asvetlov please review and/or add reviewers |
Got you, I'll pick up the PR |
# RFC1950 | ||
# bits 0..3 = CM = 0b1000 = 8 = "deflate" | ||
# bits 4..7 = CINFO = 1..7 = windows size. | ||
if not self._started_decoding and self.encoding == 'deflate' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asvetlov should we decode non-RFC compliant data? I would remove such support. But unfortunately, this will break communication with deflate-enabled aiohttp server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it for a while. I have a feeling that we need to support this mode for three years at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urllib3
used by requests
has a similar workaround: https://github.com/urllib3/urllib3/blob/9971e27e83a891ba7b832fa9e5d2f04bbcb1e65f/src/urllib3/response.py#L55-L61
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Let's merge and see if people start complaining :)
Please let me do merging myself, I want to backport it to 3.7 branch.
(cherry picked from commit 9c10806) Co-authored-by: Коренберг Марк <[email protected]>
(cherry picked from commit 9c10806) Co-authored-by: Коренберг Марк <[email protected]> Co-authored-by: Коренберг Марк <[email protected]>
What do these changes do?
Are there changes in behavior for the user?
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.