Skip to content

bpo-35292: Avoid call mimetypes.init when http.server is imported #17822

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

Merged
merged 2 commits into from
Jan 8, 2020

Conversation

aisk
Copy link
Contributor

@aisk aisk commented Jan 4, 2020

Proxy the http.server.SimpleHTTPRequestHandler.guess_type to mimetypes.guess_type so the mimetypes.init is called lazily to avoid unnecessary costs when the file is imported.

The default extensions_map is checked before call mimetypes.guess_type, with default value in mimetypes.encodings_map, for don't let mimetypes.guess_type returns the mine type besides the encoding type.

This method is implemented as https://bugs.python.org/issue35292#msg331739 said @zooba

https://bugs.python.org/issue35292

@zooba
Copy link
Member

zooba commented Jan 6, 2020

SimpleHTTPRequestHandler.extensions_map is documented (presumably in Doc/library/http.server.rst), so let's also add a note there clarifying that it "contains custom overrides for the default system mappings". Also add a `.. versionchanged: 3.9 This dictionary is no longer filled with the default system mappings, but only contains overrides." (properly formatted)

I think this deserves a NEWS entry - the failed check's Details link will help you add it.

@aisk
Copy link
Contributor Author

aisk commented Jan 8, 2020

Hi @zooba updated.

@zooba
Copy link
Member

zooba commented Jan 8, 2020

Thanks! The macOS failure doesn't seem to be your fault, and Azure Pipelines passed it, so I'll merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants