Skip to content

Commit 19cde54

Browse files
committed
ready to test
1 parent 7848730 commit 19cde54

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/http/server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def send_head(self):
719719
break
720720
else:
721721
return self.list_directory(path)
722-
ctype = self.guess_type(path, default_type)
722+
ctype = self.guess_type(path)
723723
# check for trailing "/" which should return 404. See Issue17324
724724
# The test for this was added in test_httpserver.py
725725
# However, some OS platforms accept a trailingSlash as a filename
@@ -878,7 +878,7 @@ def copyfile(self, source, outputfile):
878878
"""
879879
shutil.copyfileobj(source, outputfile)
880880

881-
def guess_type(self, path, default=self.default_content_type):
881+
def guess_type(self, path):
882882
"""Guess the type of a file.
883883
884884
Argument is a PATH (a filename).
@@ -896,7 +896,7 @@ def guess_type(self, path, default=self.default_content_type):
896896
guess = self.extensions_map.get(ext,
897897
self.extensions_map.get(ext.lower(),
898898
mimetypes.guess_type(path)))
899-
return guess or default
899+
return guess or self.default_content_type
900900

901901

902902
# Utilities for CGIHTTPRequestHandler
@@ -1252,14 +1252,16 @@ def _get_best_family(*address):
12521252

12531253
def test(HandlerClass=BaseHTTPRequestHandler,
12541254
ServerClass=ThreadingHTTPServer,
1255-
protocol="HTTP/1.0", port=8000, bind=None):
1255+
protocol="HTTP/1.0", port=8000, bind=None,
1256+
content_type=BaseHTTPRequestHandler.default_content_type):
12561257
"""Test the HTTP request handler class.
12571258
12581259
This runs an HTTP server on port 8000 (or the port argument).
12591260
12601261
"""
12611262
ServerClass.address_family, addr = _get_best_family(bind, port)
12621263
HandlerClass.protocol_version = protocol
1264+
HandlerClass.default_content_type = content_type
12631265
with ServerClass(addr, HandlerClass) as httpd:
12641266
host, port = httpd.socket.getsockname()[:2]
12651267
url_host = f'[{host}]' if ':' in host else host
@@ -1290,6 +1292,9 @@ def test(HandlerClass=BaseHTTPRequestHandler,
12901292
default='HTTP/1.0',
12911293
help='conform to this HTTP version '
12921294
'(default: %(default)s)')
1295+
parser.add_argument('-c', '--content-type', # parsed into content_type
1296+
default='application/octet-stream',
1297+
help='sets default content type for unknown extensions')
12931298
parser.add_argument('port', default=8000, type=int, nargs='?',
12941299
help='bind to this port '
12951300
'(default: %(default)s)')
@@ -1319,4 +1324,5 @@ def finish_request(self, request, client_address):
13191324
port=args.port,
13201325
bind=args.bind,
13211326
protocol=args.protocol,
1327+
content_type=args.content_type
13221328
)

0 commit comments

Comments
 (0)