duck.http.core.httpd.http2¶
Base server implementation for HTTP/2
Submodules¶
Package Contents¶
Classes¶
Base HTTP/2 server with HTTP/1.1 backward compatibility. |
Data¶
API¶
- class duck.http.core.httpd.http2.BaseHTTP2Server(addr: Tuple[str, int], application: Union[duck.app.app.App, duck.app.microapp.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.httpd.BaseServerBase HTTP/2 server with HTTP/1.1 backward compatibility.
Notes:
Supports both HTTP/2 and HTTP/1.1 protocols.
The
H2Protocolis implemented using asynchronous I/O, even in WSGI environments.In WSGI mode, request handling may be offloaded to a synchronous thread for execution outside the async context.
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
workersis 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
Trueonly when process isolation is explicitly desired and you do not require shared in-memory synchronization between workers.
- async async_handle_conn(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], flowinfo: Optional = None, scopeid: Optional = None, strictly_http2: bool = False) None¶
Main entry point to handle new connection asynchronously (supports both ipv6 and ipv4).
- Parameters:
sock – The client socket object.
addr – Client ip and port.
flowinfo – Flow info if IPv6.
scopeid – Scope id if IPv6.
strictly_http2 – Whether to srtrictly use
HTTP/2without checking if user selected it.
- async async_handle_request_data(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], request_data: duck.http.request_data.RequestData) None¶
Processes and handles a request asynchronously but logs any encountered error (but doesn’t raise exception).
- async async_start_http2_loop(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], h2_connection: h2.connection.H2Connection) None¶
This starts the asynchronous loop for handling HTTP/2 connection.
- handle_conn(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], flowinfo: Optional = None, scopeid: Optional = None, strictly_http2: bool = False) None¶
Main entry point to handle new connection (supports both ipv6 and ipv4).
- Parameters:
sock – The client socket object.
addr – Client ip and port.
flowinfo – Flow info if IPv6.
scopeid – Scope id if IPv6.
strictly_http2 – Whether to srtrictly use
HTTP/2without checking if user selected it.
- handle_request_data(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], request_data: duck.http.request_data.RequestData) None¶
Processes and handles a request but logs any encountered error (but doesn’t raise exception).
- set_h2_settings(h2_conn)¶
Sets the H2 settings on the unitiated h2 connection.
- start_http2_loop(sock: duck.utils.xsocket.xsocket, addr: Tuple[str, int], h2_connection: h2.connection.H2Connection) None¶
Starts the loop for handling HTTP/2 connection.
- duck.http.core.httpd.http2.H2_SETTINGS_REGEX¶
‘compile(…)’
- duck.http.core.httpd.http2.H2_UPGRADE_REGEX¶
‘compile(…)’
- exception duck.http.core.httpd.http2.SyncH2ProtocolStartWarning¶
Bases:
UserWarningFlagged when
H2protocol failed to start within specific timeframe in a synchronous environment.Initialization
Initialize self. See help(type(self)) for accurate signature.