Skip to content

Configuration

Every server option is exposed in three equivalent ways:

  • a CLI flag on the h2corn command
  • an H2CORN_* environment variable
  • a key in a TOML config file (passed via --config or H2CORN_CONFIG)

When the same option is provided in more than one place, the order of precedence is CLI > environment > TOML > defaults.

--host / --port and H2CORN_HOST / H2CORN_PORT are shortcuts for one TCP listener and cannot be combined with bind. --config and H2CORN_CONFIG select the TOML file; command-only controls are listed below.

Option index

OptionDefaultCLI
root_path""-r, --root-path
lifespan'auto'--lifespan
timeout_lifespan_startup60.0--timeout-lifespan-startup
timeout_lifespan_shutdown30.0--timeout-lifespan-shutdown
bind['127.0.0.1:8000']-b, --bind
uds_permissionsNone--uds-permissions
backlog1024--backlog
reuse_portFalse--reuse-port / --no-reuse-port
certfileNone--certfile
keyfileNone--keyfile
ca_certsNone--ca-certs
cert_reqs'none'--cert-reqs
pidNone--pid
userNone-u, --user
groupNone-g, --group
umaskNone-m, --umask
workers1-w, --workers
runtime_threads2--runtime-threads
loop'auto'--loop
loop_threads1--loop-threads
max_requests0--max-requests
max_requests_jitter0--max-requests-jitter
timeout_worker_healthcheck30.0--timeout-worker-healthcheck
http1True--http1 / --no-http1
access_logTrue--access-log / --no-access-log
log_format'text'--log-format
max_concurrent_streams256--max-concurrent-streams
limit_request_head_size1048576--limit-request-head-size
limit_request_line16384--limit-request-line
limit_request_fields100--limit-request-fields
limit_request_field_size32768--limit-request-field-size
h2_max_header_list_size1048576--h2-max-header-list-size
h2_max_header_block_size1048576--h2-max-header-block-size
h2_max_inbound_frame_size65536--h2-max-inbound-frame-size
h2_initial_stream_window_size8388608--h2-initial-stream-window-size
h2_initial_connection_window_size8388608--h2-initial-connection-window-size
max_request_body_size1073741824--max-request-body-size
limit_concurrency0--limit-concurrency
limit_connections0--limit-connections
timeout_handshake5.0--timeout-handshake
timeout_graceful_shutdown30.0--timeout-graceful-shutdown
timeout_keep_alive120.0--timeout-keep-alive
timeout_request_header10.0--timeout-request-header
timeout_request_body_idle60.0--timeout-request-body-idle
h2_timeout_response_stall60.0--h2-timeout-response-stall
websocket_max_message_size16777216--websocket-max-message-size
websocket_per_message_deflateTrue--websocket-per-message-deflate / --no-websocket-per-message-deflate
websocket_ping_interval60.0--websocket-ping-interval
websocket_ping_timeout30.0--websocket-ping-timeout
proxy_headersFalse--proxy-headers / --no-proxy-headers
forwarded_allow_ips['127.0.0.1', '::1', 'unix']--forwarded-allow-ips
forwarded_fields['for', 'proto']--forwarded-fields
proxy_protocol'off'--proxy-protocol
server_header'off'--server-header
date_headerTrue--date-header / --no-date-header
response_headers()--header

Application

Where the ASGI app lives and how it is loaded.

root_path

ASGI root path (to mount the application at a subpath).

Default""
CLI-r, --root-path
EnvH2CORN_ROOT_PATH
TOML keyroot_path
PrecedenceCLI > environment > TOML > default

lifespan

ASGI lifespan handling mode.

Default'auto'
CLI--lifespan
EnvH2CORN_LIFESPAN
TOML keylifespan
PrecedenceCLI > environment > TOML > default
Choicesauto, on, off

timeout_lifespan_startup

Maximum time to wait for ASGI lifespan startup in seconds. Use 0 to disable.

Default60.0
CLI--timeout-lifespan-startup
EnvH2CORN_TIMEOUT_LIFESPAN_STARTUP
TOML keytimeout_lifespan_startup
PrecedenceCLI > environment > TOML > default

timeout_lifespan_shutdown

Maximum time to wait for ASGI lifespan shutdown in seconds. Use 0 to disable.

Default30.0
CLI--timeout-lifespan-shutdown
EnvH2CORN_TIMEOUT_LIFESPAN_SHUTDOWN
TOML keytimeout_lifespan_shutdown
PrecedenceCLI > environment > TOML > default

Listeners

How h2corn accepts connections.

bind

Listener addresses to bind. Repeat the flag to add more listeners. Supports HOST:PORT, [IPv6]:PORT, unix:PATH, and fd://N.

Default['127.0.0.1:8000']
CLI-b, --bind
EnvH2CORN_BIND
TOML keybind
PrecedenceCLI > environment > TOML > default

uds_permissions

Octal mask for Unix Domain Socket permissions.

DefaultNone
CLI--uds-permissions
EnvH2CORN_UDS_PERMISSIONS
TOML keyuds_permissions
PrecedenceCLI > environment > TOML > default

backlog

Maximum number of queued connections on the listening socket.

Default1024
CLI--backlog
EnvH2CORN_BACKLOG
TOML keybacklog
PrecedenceCLI > environment > TOML > default

reuse_port

Set SO_REUSEPORT on the TCP listeners so other server processes can bind the same port — for zero-downtime deploys or independent processes. Workers of one server always share the inherited listener. TCP listeners only.

DefaultFalse
CLI--reuse-port / --no-reuse-port
EnvH2CORN_REUSE_PORT
TOML keyreuse_port
PrecedenceCLI > environment > TOML > default
Choicestrue, false

TLS

Direct TLS for TCP listeners. Leave unset when terminating TLS at a proxy.

certfile

PEM certificate chain file for direct TLS.

DefaultNone
CLI--certfile
EnvH2CORN_CERTFILE
TOML keycertfile
PrecedenceCLI > environment > TOML > default

keyfile

PEM private key file for direct TLS. Encrypted keys are not supported.

DefaultNone
CLI--keyfile
EnvH2CORN_KEYFILE
TOML keykeyfile
PrecedenceCLI > environment > TOML > default

ca_certs

PEM CA bundle used to verify client certificates for direct TLS.

DefaultNone
CLI--ca-certs
EnvH2CORN_CA_CERTS
TOML keyca_certs
PrecedenceCLI > environment > TOML > default

cert_reqs

Client certificate verification mode for direct TLS.

Default'none'
CLI--cert-reqs
EnvH2CORN_CERT_REQS
TOML keycert_reqs
PrecedenceCLI > environment > TOML > default
Choicesnone, optional, required

Process and workers

Process identity, worker pool, and lifecycle on Unix.

pid

Write the server process PID to this file.

DefaultNone
CLI--pid
EnvH2CORN_PID
TOML keypid
PrecedenceCLI > environment > TOML > default

user

User name or numeric UID for worker processes and created Unix sockets.

DefaultNone
CLI-u, --user
EnvH2CORN_USER
TOML keyuser
PrecedenceCLI > environment > TOML > default

group

Group name or numeric GID for worker processes and created Unix sockets.

DefaultNone
CLI-g, --group
EnvH2CORN_GROUP
TOML keygroup
PrecedenceCLI > environment > TOML > default

umask

Octal process umask to apply before creating files and sockets. Leave unset to preserve the inherited umask.

DefaultNone
CLI-m, --umask
EnvH2CORN_UMASK
TOML keyumask
PrecedenceCLI > environment > TOML > default

workers

Number of worker processes to spawn.

Default1
CLI-w, --workers
EnvH2CORN_WORKERS
TOML keyworkers
PrecedenceCLI > environment > TOML > default

runtime_threads

Number of Tokio runtime worker threads per worker process.

Default2
CLI--runtime-threads
EnvH2CORN_RUNTIME_THREADS
TOML keyruntime_threads
PrecedenceCLI > environment > TOML > default

loop

Python event-loop implementation: 'auto' uses uvloop when installed (the 'h2corn[uvloop]' extra), otherwise the stdlib asyncio loop. h2corn runs its I/O in Rust, so this only affects how application callbacks are scheduled.

Default'auto'
CLI--loop
EnvH2CORN_LOOP
TOML keyloop
PrecedenceCLI > environment > TOML > default
Choicesauto, asyncio, uvloop

loop_threads

Number of Python event-loop threads per worker, balanced round-robin. Requires a free-threaded (no-GIL) interpreter; ignored on GIL builds. Secondary loops require the built-in asyncio or uvloop factory (the default 'auto' resolves to one); multiple loop threads are rejected when embedded in a custom loop. Each loop runs its own ASGI lifespan and state. Composes with workers — keep workers x loop_threads at or below the core count.

Default1
CLI--loop-threads
EnvH2CORN_LOOP_THREADS
TOML keyloop_threads
PrecedenceCLI > environment > TOML > default

max_requests

Maximum number of requests or WebSocket sessions a worker should complete before retiring. Use 0 to disable.

Default0
CLI--max-requests
EnvH2CORN_MAX_REQUESTS
TOML keymax_requests
PrecedenceCLI > environment > TOML > default

max_requests_jitter

Maximum jitter added to max_requests to stagger worker retirements. Use 0 to disable.

Default0
CLI--max-requests-jitter
EnvH2CORN_MAX_REQUESTS_JITTER
TOML keymax_requests_jitter
PrecedenceCLI > environment > TOML > default

timeout_worker_healthcheck

Maximum time between worker healthcheck heartbeats before the supervisor replaces the worker. Use 0 to disable.

Default30.0
CLI--timeout-worker-healthcheck
EnvH2CORN_TIMEOUT_WORKER_HEALTHCHECK
TOML keytimeout_worker_healthcheck
PrecedenceCLI > environment > TOML > default

HTTP and resource limits

Protocol behavior and per-connection bounds.

http1

Whether to accept HTTP/1.1 connections. Intended for development; disable in production.

DefaultTrue
CLI--http1 / --no-http1
EnvH2CORN_HTTP1
TOML keyhttp1
PrecedenceCLI > environment > TOML > default
Choicestrue, false

access_log

Whether to log requests to stderr.

DefaultTrue
CLI--access-log / --no-access-log
EnvH2CORN_ACCESS_LOG
TOML keyaccess_log
PrecedenceCLI > environment > TOML > default
Choicestrue, false

log_format

Encoding for everything h2corn writes to stderr: the startup banner, worker lifecycle, errors and access records. 'json' emits one object per line so the stream can be shipped without parsing prose.

Default'text'
CLI--log-format
EnvH2CORN_LOG_FORMAT
TOML keylog_format
PrecedenceCLI > environment > TOML > default
Choicestext, json

max_concurrent_streams

Maximum active HTTP/2 streams per connection. At least 1.

Default256
CLI--max-concurrent-streams
EnvH2CORN_MAX_CONCURRENT_STREAMS
TOML keymax_concurrent_streams
PrecedenceCLI > environment > TOML > default

limit_request_head_size

Maximum total HTTP/1.1 request head size in bytes. Use 0 for no limit.

Default1048576
CLI--limit-request-head-size
EnvH2CORN_LIMIT_REQUEST_HEAD_SIZE
TOML keylimit_request_head_size
PrecedenceCLI > environment > TOML > default

limit_request_line

Maximum HTTP/1.1 request line size in bytes. Use 0 for no limit.

Default16384
CLI--limit-request-line
EnvH2CORN_LIMIT_REQUEST_LINE
TOML keylimit_request_line
PrecedenceCLI > environment > TOML > default

limit_request_fields

Maximum number of request header fields; HTTP/2 counts every decoded field, including duplicates. Use 0 for no limit.

Default100
CLI--limit-request-fields
EnvH2CORN_LIMIT_REQUEST_FIELDS
TOML keylimit_request_fields
PrecedenceCLI > environment > TOML > default

limit_request_field_size

Maximum individual HTTP/1.1 header field size in bytes. Use 0 for no limit.

Default32768
CLI--limit-request-field-size
EnvH2CORN_LIMIT_REQUEST_FIELD_SIZE
TOML keylimit_request_field_size
PrecedenceCLI > environment > TOML > default

h2_max_header_list_size

Maximum decoded HTTP/2 header list size in bytes. Use 0 for no limit.

Default1048576
CLI--h2-max-header-list-size
EnvH2CORN_H2_MAX_HEADER_LIST_SIZE
TOML keyh2_max_header_list_size
PrecedenceCLI > environment > TOML > default

h2_max_header_block_size

Maximum compressed HTTP/2 header block size in bytes while collecting HEADERS and CONTINUATION frames. Use 0 for no limit.

Default1048576
CLI--h2-max-header-block-size
EnvH2CORN_H2_MAX_HEADER_BLOCK_SIZE
TOML keyh2_max_header_block_size
PrecedenceCLI > environment > TOML > default

h2_max_inbound_frame_size

Maximum inbound HTTP/2 frame payload size to accept and advertise via SETTINGS_MAX_FRAME_SIZE.

Default65536
CLI--h2-max-inbound-frame-size
EnvH2CORN_H2_MAX_INBOUND_FRAME_SIZE
TOML keyh2_max_inbound_frame_size
PrecedenceCLI > environment > TOML > default

h2_initial_stream_window_size

HTTP/2 per-stream receive flow-control window in bytes (SETTINGS_INITIAL_WINDOW_SIZE). Controls inbound upload throughput; response throughput uses the peer-advertised send window. The default is 8 MiB.

Default8388608
CLI--h2-initial-stream-window-size
EnvH2CORN_H2_INITIAL_STREAM_WINDOW_SIZE
TOML keyh2_initial_stream_window_size
PrecedenceCLI > environment > TOML > default

h2_initial_connection_window_size

HTTP/2 connection-wide receive flow-control window in bytes. Bounds total charged upload bytes per connection; the default matches the 8 MiB stream window so one upload can use the whole connection budget.

Default8388608
CLI--h2-initial-connection-window-size
EnvH2CORN_H2_INITIAL_CONNECTION_WINDOW_SIZE
TOML keyh2_initial_connection_window_size
PrecedenceCLI > environment > TOML > default

max_request_body_size

Maximum request body size in bytes. Use 0 for no limit.

Default1073741824
CLI--max-request-body-size
EnvH2CORN_MAX_REQUEST_BODY_SIZE
TOML keymax_request_body_size
PrecedenceCLI > environment > TOML > default

limit_concurrency

Maximum number of concurrent ASGI request or session tasks per worker. Use 0 for no limit.

Default0
CLI--limit-concurrency
EnvH2CORN_LIMIT_CONCURRENCY
TOML keylimit_concurrency
PrecedenceCLI > environment > TOML > default

limit_connections

Maximum number of live client connections per worker. Use 0 for no limit.

Default0
CLI--limit-connections
EnvH2CORN_LIMIT_CONNECTIONS
TOML keylimit_connections
PrecedenceCLI > environment > TOML > default

Timeouts

Connection-level timeouts in seconds. For the optional timeouts, 0 disables the timer. For timeout_graceful_shutdown, 0 means no graceful wait — stop immediately rather than waiting for in-flight work.

timeout_handshake

Maximum time from accepting a connection to a finished PROXY preamble, TLS handshake and protocol preface, in seconds. Use 0 to disable.

Default5.0
CLI--timeout-handshake
EnvH2CORN_TIMEOUT_HANDSHAKE
TOML keytimeout_handshake
PrecedenceCLI > environment > TOML > default

timeout_graceful_shutdown

Maximum time for workers to finish in-flight requests on shutdown, in seconds.

Default30.0
CLI--timeout-graceful-shutdown
EnvH2CORN_TIMEOUT_GRACEFUL_SHUTDOWN
TOML keytimeout_graceful_shutdown
PrecedenceCLI > environment > TOML > default

timeout_keep_alive

Idle keep-alive timeout in seconds. Use 0 to disable.

Default120.0
CLI--timeout-keep-alive
EnvH2CORN_TIMEOUT_KEEP_ALIVE
TOML keytimeout_keep_alive
PrecedenceCLI > environment > TOML > default

timeout_request_header

Idle timeout in seconds while reading an HTTP request head or an HTTP/2 header block. Use 0 to disable.

Default10.0
CLI--timeout-request-header
EnvH2CORN_TIMEOUT_REQUEST_HEADER
TOML keytimeout_request_header
PrecedenceCLI > environment > TOML > default

timeout_request_body_idle

Idle timeout in seconds while reading an HTTP request body. Use 0 to disable.

Default60.0
CLI--timeout-request-body-idle
EnvH2CORN_TIMEOUT_REQUEST_BODY_IDLE
TOML keytimeout_request_body_idle
PrecedenceCLI > environment > TOML > default

h2_timeout_response_stall

Timeout in seconds for HTTP/2 response body bytes pinned behind peer flow control. Use 0 to disable.

Default60.0
CLI--h2-timeout-response-stall
EnvH2CORN_H2_TIMEOUT_RESPONSE_STALL
TOML keyh2_timeout_response_stall
PrecedenceCLI > environment > TOML > default

WebSocket

Limits and keep-alive for RFC 6455 and RFC 8441 WebSockets.

websocket_max_message_size

Maximum WebSocket message size in bytes. Defaults to 16 MiB; use 0 for no limit.

Default16777216
CLI--websocket-max-message-size
EnvH2CORN_WEBSOCKET_MAX_MESSAGE_SIZE
TOML keywebsocket_max_message_size
PrecedenceCLI > environment > TOML > default

websocket_per_message_deflate

Whether to negotiate permessage-deflate for WebSockets when the client offers it.

DefaultTrue
CLI--websocket-per-message-deflate / --no-websocket-per-message-deflate
EnvH2CORN_WEBSOCKET_PER_MESSAGE_DEFLATE
TOML keywebsocket_per_message_deflate
PrecedenceCLI > environment > TOML > default
Choicestrue, false

websocket_ping_interval

Interval in seconds between server WebSocket ping frames. Use 0 to disable.

Default60.0
CLI--websocket-ping-interval
EnvH2CORN_WEBSOCKET_PING_INTERVAL
TOML keywebsocket_ping_interval
PrecedenceCLI > environment > TOML > default

websocket_ping_timeout

Time limit in seconds to wait for a pong after a server WebSocket ping. Use 0 to disable. No effect while websocket_ping_interval is 0.

Default30.0
CLI--websocket-ping-timeout
EnvH2CORN_WEBSOCKET_PING_TIMEOUT
TOML keywebsocket_ping_timeout
PrecedenceCLI > environment > TOML > default

Proxy and response headers

Trust boundaries with the upstream proxy and default response headers.

proxy_headers

Enable forwarding-header processing for peers in forwarded_allow_ips; forwarded_fields selects the facts and dialect.

DefaultFalse
CLI--proxy-headers / --no-proxy-headers
EnvH2CORN_PROXY_HEADERS
TOML keyproxy_headers
PrecedenceCLI > environment > TOML > default
Choicestrue, false

forwarded_allow_ips

Allowed IPs or networks (in CIDR notation) for proxy headers. Use '*' to trust all.

Default['127.0.0.1', '::1', 'unix']
CLI--forwarded-allow-ips
EnvH2CORN_FORWARDED_ALLOW_IPS
TOML keyforwarded_allow_ips
PrecedenceCLI > environment > TOML > default

forwarded_fields

Forwarding facts to interpret from a trusted proxy: for, proto, host, port, prefix select X-Forwarded-* fields; forwarded selects RFC 7239 Forwarded. The dialects cannot be combined.

Default['for', 'proto']
CLI--forwarded-fields
EnvH2CORN_FORWARDED_FIELDS
TOML keyforwarded_fields
PrecedenceCLI > environment > TOML > default

proxy_protocol

Expect HAProxy's PROXY protocol on inbound connections.

Default'off'
CLI--proxy-protocol
EnvH2CORN_PROXY_PROTOCOL
TOML keyproxy_protocol
PrecedenceCLI > environment > TOML > default
Choicesoff, v1, v2

server_header

Identify the server in a Server header: off sends none, on sends the name, full adds the version. Any other value goes through --header, which also wins over this.

Default'off'
CLI--server-header
EnvH2CORN_SERVER_HEADER
TOML keyserver_header
PrecedenceCLI > environment > TOML > default
Choicesoff, on, full

date_header

Whether to add a default Date header when the application sets none.

DefaultTrue
CLI--date-header / --no-date-header
EnvH2CORN_DATE_HEADER
TOML keydate_header
PrecedenceCLI > environment > TOML > default
Choicestrue, false

response_headers

Default response headers in lowercase name: value form, added only when the application did not set that name itself. Repeat the flag to add more headers.

Default()
CLI--header
EnvH2CORN_RESPONSE_HEADERS
TOML keyresponse_headers
PrecedenceCLI > environment > TOML > default

Command-only CLI controls

These flags control application loading, development reload, or process actions rather than a Config value.

Command-only flags: -h, --help

Print command help, then exit.

Command-only flags: -c, --config

Select the TOML file; H2CORN_CONFIG selects the same file.

Command-only flags: --version

Print the installed h2corn version, then exit.

Command-only flags: --check-config

Validate configuration and TLS, then exit.

Command-only flags: --print-config

Print the fully resolved configuration, then exit.

Command-only flags: --factory

Call the target as a zero-argument app factory.

Command-only flags: --app-dir

Import the target from this directory.

Command-only flags: --env-file

Load application environment before import.

Command-only flags: --reload

Watch application files and restart one development worker.

Command-only flags: --reload-dir

Add a development reload directory; repeatable.

Command-only flags: --reload-include

Add a development reload glob; repeatable.

Command-only flags: --reload-exclude

Add a development reload exclusion; repeatable.

Command-only flags: --host

TCP host convenience input for bind; H2CORN_HOST is equivalent when H2CORN_BIND is unset.

Command-only flags: -p, --port

TCP port convenience input for bind; H2CORN_PORT is equivalent when H2CORN_BIND is unset.

Building a Config programmatically

Config is a frozen dataclass; instantiate it directly or use Config.from_env(), Config.from_mapping(), or Config.from_toml(). See the Config API reference for their signatures.