A WSGI server that that handles one request at a time. Use :func:`make_server` to create a server instance.
| 699 | |
| 700 | |
| 701 | class BaseWSGIServer(HTTPServer): |
| 702 | """A WSGI server that that handles one request at a time. |
| 703 | |
| 704 | Use :func:`make_server` to create a server instance. |
| 705 | """ |
| 706 | |
| 707 | multithread = False |
| 708 | multiprocess = False |
| 709 | request_queue_size = LISTEN_QUEUE |
| 710 | allow_reuse_address = True |
| 711 | |
| 712 | def __init__( |
| 713 | self, |
| 714 | host: str, |
| 715 | port: int, |
| 716 | app: WSGIApplication, |
| 717 | handler: type[WSGIRequestHandler] | None = None, |
| 718 | passthrough_errors: bool = False, |
| 719 | ssl_context: _TSSLContextArg | None = None, |
| 720 | fd: int | None = None, |
| 721 | ) -> None: |
| 722 | if handler is None: |
| 723 | handler = WSGIRequestHandler |
| 724 | |
| 725 | # If the handler doesn't directly set a protocol version and |
| 726 | # thread or process workers are used, then allow chunked |
| 727 | # responses and keep-alive connections by enabling HTTP/1.1. |
| 728 | if "protocol_version" not in vars(handler) and ( |
| 729 | self.multithread or self.multiprocess |
| 730 | ): |
| 731 | handler.protocol_version = "HTTP/1.1" |
| 732 | |
| 733 | self.host = host |
| 734 | self.port = port |
| 735 | self.app = app |
| 736 | self.passthrough_errors = passthrough_errors |
| 737 | |
| 738 | self.address_family = address_family = select_address_family(host, port) |
| 739 | server_address = get_sockaddr(host, int(port), address_family) |
| 740 | |
| 741 | # Remove a leftover Unix socket file from a previous run. Don't |
| 742 | # remove a file that was set up by run_simple. |
| 743 | if address_family == af_unix and fd is None: |
| 744 | server_address = t.cast(str, server_address) |
| 745 | |
| 746 | if os.path.exists(server_address): |
| 747 | os.unlink(server_address) |
| 748 | |
| 749 | # Bind and activate will be handled manually, it should only |
| 750 | # happen if we're not using a socket that was already set up. |
| 751 | super().__init__( |
| 752 | server_address, # type: ignore[arg-type] |
| 753 | handler, |
| 754 | bind_and_activate=False, |
| 755 | ) |
| 756 | |
| 757 | if fd is None: |
| 758 | # No existing socket descriptor, do bind_and_activate=True. |