duck.http.core.httpd.servers

Module containing server classes.

Module Contents

Classes

HTTPServer

HTTPServer class for handling requests.

MicroHTTPServer

MicroHTTPServer class.

Data

BaseServer

API

duck.http.core.httpd.servers.BaseServer

None

class duck.http.core.httpd.servers.HTTPServer(addr: Tuple[str, int], application: Union[App, MicroApp], domain: str = None, uses_ipv6: bool = False, enable_ssl: bool = False, ssl_params: Optional[Dict] = None, no_logs: bool = False, workers: Optional[int] = None, force_worker_processes: bool = False)

Bases: duck.http.core.httpd.servers.BaseServer

HTTPServer class for handling requests.

Initialization

Initialise the server instance.

Parameters:
  • addr – Tuple of address and port.

  • application – The application that is using this server. Can be either duck main app or micro app.

  • domain – The server domain.

  • uses_ipv6 – Whether If the server is on (IPV6)

  • enable_ssl – Whether to enable HTTPS.

  • ssl_params – Dictionary containing ssl parameters to parse to SSLSocket. If None, default ones will be used.

  • no_logs – Whether to disable logging.

  • workers – Number of workers to use. None will disable workers.

  • force_worker_processes

    Determines whether to use worker processes instead of the default worker threads. By default, when workers is greater than 1, the server will use worker threads. Threads avoid cross-process synchronization issues—such as component registry mismatches (e.g., issues with Lively components) that occur when state lives in separate processes.

    Set this flag to True only when process isolation is explicitly desired and you do not require shared in-memory synchronization between workers.

__instances: int

0

This is the current number of server instances.

reload_ssl_context() bool

Reloads only the SSL certificate and key files. Keeps the base context (protocols, ciphers, etc.) intact.

Raises:
  • RuntimeError – If _ssl_context is not set and ssl_wrap_socket has already been used.

  • Exception – Any other exception on error.

Returns:

Whether reload has actually been performed.

Return type:

bool

… admonition:: Notes

This does nothing if _ssl_context not set.

ssl_wrap_socket(client_socket: socket.socket) duck.utils.xsocket.ssl_xsocket

Wraps client socket with SSL context.

class duck.http.core.httpd.servers.MicroHTTPServer(addr: Tuple[str, int], microapp: MicroApp, domain: str = None, uses_ipv6: bool = False, enable_ssl: bool = False, ssl_params: bool = None, no_logs: bool = True, workers: Optional[int] = None, force_worker_processes: bool = False)

Bases: duck.http.core.httpd.httpd.BaseMicroServer, duck.http.core.httpd.servers.HTTPServer

MicroHTTPServer class.

Initialization

Initialise the server instance.

Parameters:
  • addr – Tuple of address and port.

  • application – The application that is using this server. Can be either duck main app or micro app.

  • domain – The server domain.

  • uses_ipv6 – Whether If the server is on (IPV6)

  • enable_ssl – Whether to enable HTTPS.

  • ssl_params – Dictionary containing ssl parameters to parse to SSLSocket. If None, default ones will be used.

  • no_logs – Whether to disable logging.

  • workers – Number of workers to use. None will disable workers.

  • force_worker_processes

    Determines whether to use worker processes instead of the default worker threads. By default, when workers is greater than 1, the server will use worker threads. Threads avoid cross-process synchronization issues—such as component registry mismatches (e.g., issues with Lively components) that occur when state lives in separate processes.

    Set this flag to True only when process isolation is explicitly desired and you do not require shared in-memory synchronization between workers.