bpo-5054: CGIHTTPRequestHandler.run_cgi() HTTP_ACCEPT improperly parsed by orsenthil · Pull Request #23638 · python/cpython
from collections import OrderedDict from http.server import BaseHTTPRequestHandler, HTTPServer, \ SimpleHTTPRequestHandler, CGIHTTPRequestHandler from http import server, HTTPStatus
cgi_file6 = """\ #!%s import os
print("Content-type: text/plain") print() print(repr(os.environ)) """
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0, "This test can't be run reliably as root (issue #13308).")
self.file6_path = os.path.join(self.cgi_dir, 'file6.py') with open(self.file6_path, 'w', encoding='utf-8') as file6: file6.write(cgi_file6 % self.pythonexe) os.chmod(self.file6_path, 0o777)
os.chdir(self.parent_dir)
def tearDown(self):
def test_accept(self): browser_accept = \ 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' tests = ( ((('Accept', browser_accept),), browser_accept), ((), ''), # Hack case to get two values for the one header ((('Accept', 'text/html'), ('ACCEPT', 'text/plain')), 'text/html,text/plain'), ) for headers, expected in tests: headers = OrderedDict(headers) with self.subTest(headers): res = self.request('/cgi-bin/file6.py', 'GET', headers=headers) self.assertEqual(http.HTTPStatus.OK, res.status) expected = f"'HTTP_ACCEPT': {expected!r}" self.assertIn(expected.encode('ascii'), res.read())
class SocketlessRequestHandler(SimpleHTTPRequestHandler):