summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorAn Long <aisk@users.noreply.github.com>2020-01-08 18:28:14 (GMT)
committerSteve Dower <steve.dower@python.org>2020-01-08 18:28:14 (GMT)
commit5907e61a8d4da6d0f11bf1062d6d17484560a15e (patch)
tree863c1b99fe9b5701b401d0b6de451cf703272a71 /Lib/http
parent2e6a8efa837410327b593dc83c57492253b1201e (diff)
downloadcpython-5907e61a8d4da6d0f11bf1062d6d17484560a15e.zip
cpython-5907e61a8d4da6d0f11bf1062d6d17484560a15e.tar.gz
cpython-5907e61a8d4da6d0f11bf1062d6d17484560a15e.tar.bz2
bpo-35292: Avoid calling mimetypes.init when http.server is imported (GH-17822)
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index c6e5ed6..2d74b95 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -639,6 +639,12 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
"""
server_version = "SimpleHTTP/" + __version__
+ extensions_map = _encodings_map_default = {
+ '.gz': 'application/gzip',
+ '.Z': 'application/octet-stream',
+ '.bz2': 'application/x-bzip2',
+ '.xz': 'application/x-xz',
+ }
def __init__(self, *args, directory=None, **kwargs):
if directory is None:
@@ -866,25 +872,16 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
slow) to look inside the data to make a better guess.
"""
-
base, ext = posixpath.splitext(path)
if ext in self.extensions_map:
return self.extensions_map[ext]
ext = ext.lower()
if ext in self.extensions_map:
return self.extensions_map[ext]
- else:
- return self.extensions_map['']
-
- if not mimetypes.inited:
- mimetypes.init() # try to read system mime.types
- extensions_map = mimetypes.types_map.copy()
- extensions_map.update({
- '': 'application/octet-stream', # Default
- '.py': 'text/plain',
- '.c': 'text/plain',
- '.h': 'text/plain',
- })
+ guess, _ = mimetypes.guess_type(path)
+ if guess:
+ return guess
+ return 'application/octet-stream'
# Utilities for CGIHTTPRequestHandler