@@ -727,6 +727,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
727727 """
728728
729729 server_version = "SimpleHTTP"
730+ default_content_type = "application/octet-stream"
730731 index_pages = ("index.html" , "index.htm" )
731732 extensions_map = _encodings_map_default = {
732733 '.gz' : 'application/gzip' ,
@@ -974,7 +975,7 @@ def guess_type(self, path):
974975 guess , _ = mimetypes .guess_file_type (path )
975976 if guess :
976977 return guess
977- return 'application/octet-stream'
978+ return self . default_content_type
978979
979980
980981nobody = None
@@ -1010,9 +1011,10 @@ def _get_best_family(*address):
10101011 return family , sockaddr
10111012
10121013
1013- def test (HandlerClass = BaseHTTPRequestHandler ,
1014+ def test (HandlerClass = SimpleHTTPRequestHandler ,
10141015 ServerClass = ThreadingHTTPServer ,
10151016 protocol = "HTTP/1.0" , port = 8000 , bind = None ,
1017+ content_type = SimpleHTTPRequestHandler .default_content_type ,
10161018 tls_cert = None , tls_key = None , tls_password = None ):
10171019 """Test the HTTP request handler class.
10181020
@@ -1021,6 +1023,7 @@ def test(HandlerClass=BaseHTTPRequestHandler,
10211023 """
10221024 ServerClass .address_family , addr = _get_best_family (bind , port )
10231025 HandlerClass .protocol_version = protocol
1026+ HandlerClass .default_content_type = content_type
10241027
10251028 if tls_cert :
10261029 server = ServerClass (addr , HandlerClass , certfile = tls_cert ,
@@ -1060,6 +1063,10 @@ def _main(args=None):
10601063 default = 'HTTP/1.0' ,
10611064 help = 'conform to this HTTP version '
10621065 '(default: %(default)s)' )
1066+ parser .add_argument ('--content-type' ,
1067+ default = SimpleHTTPRequestHandler .default_content_type ,
1068+ help = 'default content type for unknown extensions '
1069+ '(default: %(default)s)' )
10631070 parser .add_argument ('--tls-cert' , metavar = 'PATH' ,
10641071 help = 'path to the TLS certificate chain file' )
10651072 parser .add_argument ('--tls-key' , metavar = 'PATH' ,
@@ -1112,6 +1119,7 @@ class HTTPSDualStackServer(DualStackServerMixin, ThreadingHTTPSServer):
11121119 port = args .port ,
11131120 bind = args .bind ,
11141121 protocol = args .protocol ,
1122+ content_type = args .content_type ,
11151123 tls_cert = args .tls_cert ,
11161124 tls_key = args .tls_key ,
11171125 tls_password = tls_key_password ,
0 commit comments