-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add support for brotli content encoding via brotlipy package #1532
Conversation
I wish our architecture was more pluggable. :) |
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.
Getting you some early review comments.
.gitignore
Outdated
@@ -6,3 +6,4 @@ | |||
/dist | |||
/build | |||
/docs/_build | |||
/venv |
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 revert this change as it's not critical for this patch.
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.
Yes, that's temporary and won't go to the final commit.
@@ -118,6 +138,9 @@ def _get_decoder(mode): | |||
if mode == 'gzip': |
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 do a if and elif chain here for better readability.
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.
There are competing schools of thought regarding this: one is about having "if-elif-elif-else" wherever you can, the other is about "if your "if" ends with a return, there is no need to add "else" and an extra level of indentation".
I felt like the latter was applied in this section of the code, but I'm happy to change it if you like.
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 leave the code how it is.
src/urllib3/response.py
Outdated
def decompress(self, data): | ||
try: | ||
return self._obj.decompress(data) | ||
except brotli.Error as err: |
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.
No need to re-raise here if we're adding brotli.Error
below?
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 catch!
src/urllib3/response.py
Outdated
@@ -154,7 +177,7 @@ class is also compatible with the Python standard library's :mod:`io` | |||
value of Content-Length header, if present. Otherwise, raise error. | |||
""" | |||
|
|||
CONTENT_DECODERS = ['gzip', 'deflate'] | |||
CONTENT_DECODERS = ['gzip', 'deflate', 'br'] |
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.
We need to conditionally add 'br'
to CONTENT_DECODERS
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.
Yes, thank you
src/urllib3/util/request.py
Outdated
import brotli | ||
except ImportError: | ||
brotli = None | ||
if brotli is not None: |
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.
We can roll this +=
logic within the try
/except
.
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.
Sure
test/__init__.py
Outdated
@@ -74,6 +78,16 @@ def wrapper(*args, **kwargs): | |||
return wrapper | |||
|
|||
|
|||
def only_with_brotlipy(): |
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 the semantics of notX
and requiresX
consistent.
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.
Sure
tox.ini
Outdated
@@ -1,9 +1,11 @@ | |||
[tox] | |||
envlist = flake8-py3, py27, py34, py35, py36, py37, py38, pypy | |||
envlist = flake8-py3, py27, py34, py35, py36, py37, py38, pypy, py{27,38}-nobrotli |
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.
Wish there was a better way to handle this.
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 am not very good with tox, and open to constructive criticism here.
0cf2903
to
2349d7e
Compare
Codecov Report
@@ Coverage Diff @@
## master #1532 +/- ##
==========================================
- Coverage 99.94% 99.67% -0.28%
==========================================
Files 22 22
Lines 1806 1826 +20
==========================================
+ Hits 1805 1820 +15
- Misses 1 6 +5
Continue to review full report at Codecov.
|
We can try and go the other route, that is to first introduce a pluggable decoder package and then add brotli on top of it. |
2349d7e
to
62bc5cf
Compare
@immerrr The other route isn't great either because the default should be "always-on" if Few other things I didn't comment about:
|
62bc5cf
to
194c440
Compare
@sethmlarson pluggable architecture could be "always-on if available", no problem. I'll put together a POC shortly. |
aa0fbf4
to
59d3e2f
Compare
Done
And done. Not sure what do make of the error in "docs" target in Travis. |
I'm unsure what to make of it either. Will have to investigate. |
The DOCS failure on Travis and the Python 2.7 failure on Appveyor look like temporary network failures |
59d3e2f
to
80ec3b2
Compare
Looks like the docs failure is persistent. Actually, there are two. One is this one:
The other is the fact that intersphinx fails to print that message to show what exactly has failed and prints a quite confusing
|
Once you have the
|
Looks like a problem with dependencies that were vendored with requests until 2.16, if I update requests to 2.16 it looks OK |
80ec3b2
to
07de500
Compare
Found the problem. I had to explicitly name "extras" on the "docs" target in tox.ini after overriding them conditionally in the generic |
Nice catch! |
aca64f4
to
22a9ad3
Compare
Fixed all outstanding issues, I believe this PR is ready for another round of reviews. |
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.
Looking real good, just one comment from me.
setup.py
Outdated
@@ -64,6 +64,9 @@ | |||
], | |||
test_suite='test', | |||
extras_require={ | |||
'brotli': [ | |||
'brotlipy', |
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.
Can we at least set a minimum bound here?
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 recommend >=0.6.0 so we can use brotli.Error
and we fix a decompress()
bug. See: https://github.com/python-hyper/brotlipy/blob/master/HISTORY.rst#060-2016-09-08
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.
Done
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.
Sorry @immerrr I edited my comment as you pushed. Would you mind increasing to 0.6.0?
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.
Sure
ad1e66f
to
31b4384
Compare
31b4384
to
60190e6
Compare
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.
Pending CI passing I think this looks ready to merge.
Transient failures on CI |
Thanks @immerrr! 🎉 |
Thank you for helping me to see it through. |
Any idea when this might be released? |
This is A PR to add optional support for
brotlipy
package to implement support for brotli content encoding. There was another PR that attempted to do this, #713, but it was closed during the PR bankruptcy and never reopened back. This PR is slightly different, because unlike #713 it doesn't go the way of creating an extensible decoders subpackage only adding the bare minimum.