-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-35292: Lazily inject system mime.types into SimpleHTTPRequestHandler.extensions_map #11036
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
Conversation
…ler.extensions_map
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.
A couple of things to fix, but view my suggestion on the bug in case you like my next idea better :)
extensions_map = { | ||
'': 'application/octet-stream', # Default, | ||
**mimetypes.types_map | ||
} |
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 is missing the .py
, .c
and .h
defaults as well. They certainly aren't guaranteed to be available.
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.
Oh, I didn't see that types_map
is already partially initialized. This bit is fine then - leave it as it is.
@@ -857,6 +862,9 @@ def guess_type(self, path): | |||
slow) to look inside the data to make a better guess. | |||
|
|||
""" | |||
if not mimetypes.inited: | |||
mimetypes.init() # try to read system mime.types | |||
self.extensions_map.update(mimetypes.types_map) |
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 is actually going to update in the wrong order - it will overwrite any manual overrides with the original type.
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 will overwrite any manual overrides with the original type
By manual overrides, are you talking about the '': 'application/octet-stream'
pair?
Maybe we should replace this line with:
self.extensions_map = {
'': 'application/octet-stream',
**mimetypes.types_map
}
What do you think?
@onyb Did you had time to check for https://bugs.python.org/issue35292#msg331739? I actually think the idea is good. |
The fix in #17822 makes this one unnecessary. Thanks for working on it, though! |
Important changes
extension_map
class attribute ofSimpleHTTPRequestHandler
is initialized with a default mapping, and some static mapping already available inmimetypes.types_map
.SimpleHTTPRequestHandler.guess_type
method..py
extension is nowtext/x-python
instead oftext/plain
.https://bugs.python.org/issue35292