Test the HTTP request handler class. This runs an HTTP server on port 8000 (or the port argument).
(HandlerClass=BaseHTTPRequestHandler,
ServerClass=ThreadingHTTPServer,
protocol="HTTP/1.0", port=8000, bind=None,
tls_cert=None, tls_key=None, tls_password=None)
| 973 | |
| 974 | |
| 975 | def test(HandlerClass=BaseHTTPRequestHandler, |
| 976 | ServerClass=ThreadingHTTPServer, |
| 977 | protocol="HTTP/1.0", port=8000, bind=None, |
| 978 | tls_cert=None, tls_key=None, tls_password=None): |
| 979 | """Test the HTTP request handler class. |
| 980 | |
| 981 | This runs an HTTP server on port 8000 (or the port argument). |
| 982 | |
| 983 | """ |
| 984 | ServerClass.address_family, addr = _get_best_family(bind, port) |
| 985 | HandlerClass.protocol_version = protocol |
| 986 | |
| 987 | if tls_cert: |
| 988 | server = ServerClass(addr, HandlerClass, certfile=tls_cert, |
| 989 | keyfile=tls_key, password=tls_password) |
| 990 | else: |
| 991 | server = ServerClass(addr, HandlerClass) |
| 992 | |
| 993 | with server as httpd: |
| 994 | host, port = httpd.socket.getsockname()[:2] |
| 995 | url_host = f'[{host}]' if ':' in host else host |
| 996 | protocol = 'HTTPS' if tls_cert else 'HTTP' |
| 997 | print( |
| 998 | f"Serving {protocol} on {host} port {port} " |
| 999 | f"({protocol.lower()}://{url_host}:{port}/) ..." |
| 1000 | ) |
| 1001 | try: |
| 1002 | httpd.serve_forever() |
| 1003 | except KeyboardInterrupt: |
| 1004 | print("\nKeyboard interrupt received, exiting.") |
| 1005 | sys.exit(0) |
| 1006 | |
| 1007 | |
| 1008 | def _main(args=None): |
no test coverage detected
searching dependent graphs…