-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
bpo-30576 : Add HTTP compression support to http.server #2078
Conversation
# Conflicts: # Misc/NEWS
Doc/whatsnew/3.7.rst
Outdated
@@ -219,6 +227,12 @@ math | |||
New :func:`~math.remainder` function, implementing the IEEE 754-style remainder | |||
operation. (Contributed by Mark Dickinson in :issue:`29962`.) | |||
|
|||
mimetypes |
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 be in an other PR.
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.
Same comment as below about extension .json
Lib/http/server.py
Outdated
@@ -7,6 +7,7 @@ | |||
It does, however, optionally implement HTTP/1.1 persistent connections, | |||
as of version 0.3. | |||
|
|||
|
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.
remove this line
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 in f9963f0
Lib/mimetypes.py
Outdated
@@ -439,6 +439,7 @@ def _default_mime_types(): | |||
'.jpeg' : 'image/jpeg', | |||
'.jpg' : 'image/jpeg', | |||
'.js' : 'application/javascript', | |||
'.json' : 'application/json', |
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.
in an other PR ? it's out of context
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.
It's not totally out of context : files with extension .json are obvious candidates for compression, this is why I have included this minor change in mimetypes, thinking that it doesn't deserve a specific PR. But if you think it's better to open another one, I will.
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, any change to mimetypes should be a separate issue/PR.
self.cwd = os.getcwd() | ||
basetempdir = tempfile.gettempdir() | ||
os.chdir(basetempdir) | ||
self.data = 10 * b'We are the knights who say Ni!' |
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.
and a test with a big file ?
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 in 586b8c3
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.
@matrixise
Are you ok with the changes made since the first version, or do you see other things to do before the PR can be merged ?
If you think a separate PR is better for mimetypes I will submit it, it's just that I prefered to avoid the overhead of reviewing 2 PRs instead of one.
# Conflicts: # Misc/NEWS
# Conflicts: # Misc/NEWS
# Conflicts: # Misc/NEWS
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 already told you that a separate issue and PR are required for any change to mimetypes. Make me nosy on the issue, please (r.david.murray on the bug tracker).
Lib/mimetypes.py
Outdated
@@ -439,6 +439,7 @@ def _default_mime_types(): | |||
'.jpeg' : 'image/jpeg', | |||
'.jpg' : 'image/jpeg', | |||
'.js' : 'application/javascript', | |||
'.json' : 'application/json', |
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, any change to mimetypes should be a separate issue/PR.
@bitdancer |
@bitdancer @matrixise |
…o {}, but allow compression in case a subclass extends it.
…by assertNotIn(a, b)
… (if any) at random.
…line option "gzip" by "compressed"
@vadmium |
@rhettinger |
Anyone able to review this? Ended up running against an issue today where this would have been nice to have. |
+1 I'd be great to see this one land 👍 |
Thanks for the PR, @PierreQuentel , but I'm closing this as me and various other core devs can't quite muster enough excitement about what this feature brings to warrant wanting to support it for a couple of decades. |
Brett, this is a capability of HTTP that has existed for decades that
Python still doesn’t support. It’s shipped with every major browser and web
server in the last 20 years. Part of the reason people are moving to Golang
is for its superior HTTP libraries. I think this PR deserves a second look.
…On Tue, Sep 11, 2018 at 4:06 PM Brett Cannon ***@***.***> wrote:
Closed #2078 <#2078>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2078 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGrYNlZcQqpNy7_5TZC9MKPtGc49RJ_ks5uaEHpgaJpZM4N2HSc>
.
|
+1 |
The module is released as httpcompressionserver on PyPI. |
@PierreQuentel Great! thanks for this, I’ll try it out soon. I have a suggestion for running (usage command) the module, I loved the simplicity of http.server - so was thinking if this could be so too, like http.eserver (e for encoded from html header or maybe c for compression). |
The Pull Request add support of HTTP compression to the built-in HTTP server. For some files (html, css, js, json...), compression reduces network load by sending the gzipped content instead of the original content. Most browsers support it.
The main change in is method
send_head()
ofSimpleHTTPRequestHandler
. If the request includes the headerAccept-Encoding
and its content includes "gzip", and if the content type determined by the file extension is in a list of compressed types, then the response includes the headerContent-Encoding
set to "gzip", the content type is set to that of the gzipped content, and the file object returned bysend_head()
points to the gzipped content.If the original file is small, its content is loaded in memory and gzipped, the file object is and instance of
io.BytesIO
. If it is big, the gzipped content is stored in a temporary file.The PR changes module mimetypes to add the mapping of extension ".json" to content type "application/json".
https://bugs.python.org/issue30576