[proxy] github.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public

Conversation

Copy link
Contributor

onyb commented Dec 8, 2018

Important changes

  • When http.server is imported, the extension_map class attribute of SimpleHTTPRequestHandler is initialized with a default mapping, and some static mapping already available in mimetypes.types_map.
  • The time delay in importing the aforementioned module is now deferred to the first call of SimpleHTTPRequestHandler.guess_type method.
  • The mimetype for .py extension is now text/x-python instead of text/plain.

https://bugs.python.org/issue35292

Copy link
Member

zooba left a 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
}
Copy link
Member

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.

Copy link
Member

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.

"""
if not mimetypes.inited:
mimetypes.init() # try to read system mime.types
self.extensions_map.update(mimetypes.types_map)
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

@onyb Did you had time to check for https://bugs.python.org/issue35292#msg331739? I actually think the idea is good.

Copy link
Member

zooba commented Jan 8, 2020

The fix in #17822 makes this one unnecessary. Thanks for working on it, though!

zooba closed this Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants