gh-113471: Add custom default Content-Type to http.server (#113475)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: donBarbos <donbarbos@proton.me>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
John Comeau 2026-04-30 08:00:48 -07:00 committed by GitHub
parent f0e90d78eb
commit cc5f8b5434
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 49 additions and 2 deletions

View file

@ -1379,6 +1379,7 @@ class CommandLineTestCase(unittest.TestCase):
'protocol': default_protocol,
'port': default_port,
'bind': default_bind,
'content_type': 'application/octet-stream',
'tls_cert': None,
'tls_key': None,
'tls_password': None,
@ -1447,6 +1448,16 @@ def test_protocol_flag(self, mock_func):
mock_func.assert_called_once_with(**call_args)
mock_func.reset_mock()
@mock.patch('http.server.test')
def test_content_type_flag(self, mock_func):
content_types = ['text/html', 'text/plain', 'application/json']
for content_type in content_types:
with self.subTest(content_type=content_type):
self.invoke_httpd('--content-type', content_type)
call_args = self.args | dict(content_type=content_type)
mock_func.assert_called_once_with(**call_args)
mock_func.reset_mock()
@unittest.skipIf(ssl is None, "requires ssl")
@mock.patch('http.server.test')
def test_tls_cert_and_key_flags(self, mock_func):