-
-
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
Support brotli compression of HTTP responses #2945
Conversation
Thanks for PR. |
cfd1a80
to
91e5dc3
Compare
Codecov Report
@@ Coverage Diff @@
## master #2945 +/- ##
==========================================
- Coverage 97.99% 97.81% -0.18%
==========================================
Files 40 41 +1
Lines 7520 7613 +93
Branches 1318 1333 +15
==========================================
+ Hits 7369 7447 +78
- Misses 48 56 +8
- Partials 103 110 +7
Continue to review full report at Codecov.
|
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.
Good work.
I have some notes about implementation but very like the overall design.
Switching to ContentCoding
usage instead of strings in both client and server API would be nice (but we should keep supporting strings during deprecation period)
|
||
@classmethod | ||
def get_from_accept_encoding(cls, accept_encoding): | ||
accept_encoding = accept_encoding.lower() |
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.
Would be nice to parse AcceptEncoding
header properly and respect weights instead of selecting the first supported compression based on server preference order.
Multiple Accept-Encoding
headers are allowed by HTTP spec also.
We can either accept a list of headers (req.headers.getall('Accept-Encoding')
) or headers
param itself.
return coding | ||
|
||
@classmethod | ||
def values(cls): |
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.
What is the usage of the method?
Could we utilize Enum.__members__
or another existing Enum
API?
return _values | ||
|
||
|
||
def get_compressor(encoding): |
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.
Could we switch here to ContentCoding
enum? Maybe make it a ContentCoding
member function?
The same for decompressor.
self._finished = False | ||
|
||
@classmethod | ||
def gzip(cls): |
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.
I prefer making GZipCompressor
class derived from ZlibCompressor
over class methods for gzip and deflate compressors building.
return self._compress.finish() | ||
|
||
|
||
def decompress(encoding, data): |
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.
As I see the function is used only once in multipart
module.
Maybe direct usage of decompressor classes there is enough?
Just a status update: have been busy lately, but planning to finish by the end of the week. |
Sounds good
|
Is there a progress on it? |
HI |
No problem |
There are many conflicts now. |
I'll close this one and reopen when I'm ready. Really sorry, don't have enough free time currently. |
What do these changes do?
This PR adds support for
br
(brotli) content-type compression.I have also refactored compressors and decompressors to a separate module (aiohttp.compression) because there are some differences between zlib's and brotli's intefraces.
Related tests have also been refactored a bit, now pytest's parametrization is used more aggressively.
For now brotli compression of websocket responses is not supported,
Are there changes in behavior for the user?
aiohttp now can compress responses using brotli compression algorithm if
brotlipy
is installed.Related issue number
Closes #2518