Configuration

Set the properties on the HTTPServer node before you call start().

Server properties

PropertyDefaultDescription
max_connections100Maximum concurrent connections
max_request_size10 MBMaximum request body size
idle_timeout30 sClose idle connections after this time
handshake_timeout10 sTLS handshake timeout
max_keep_alive_requests100Maximum requests per keep-alive connection
poll_interval0.05 sConnection polling frequency
bind_address127.0.0.1IP address to bind. Use 0.0.0.0 for all interfaces
drain_timeout5 sWait for in-flight requests during shutdown()
server.max_connections = 500
server.idle_timeout = 60.0
server.bind_address = "0.0.0.0"   # expose beyond localhost

Enable HTTPS

Call setup_tls() before start(). Pass a PEM certificate and a PEM key:

func _ready() -> void:
    var err := server.setup_tls("res://cert.pem", "res://key.pem")
    if err == OK:
        server.start(443)

The method returns an Error code when it fails to load the certificate or the key.

Lifecycle signals

The server emits these signals:

SignalEmitted when
server_started(port)The server starts listening
server_stoppedThe server stops
client_connected(ip)A client connects
client_disconnected(ip)A client disconnects
request_handled(request, response)A request completes
websocket_connected(connection)A WebSocket upgrades
websocket_disconnected(connection, code, reason)A WebSocket closes

Graceful shutdown

Call stop() to close all connections and stop listening. The server also calls stop() when the node leaves the scene tree:

func _exit_tree() -> void:
    server.stop()

Use shutdown() to stop accepting new connections and wait for in-flight requests to finish before closing. It waits up to drain_timeout seconds, then force-closes:

server.shutdown()        # waits drain_timeout (5 s by default)
server.shutdown(20.0)    # custom wait

Protocol defaults

The server sets a Server and Date header on every response. Requests that exceed max_request_size return 413 Payload Too Large instead of dropping the socket. Stalled requests return 408 Request Timeout. When the connection pool is full, new peers receive 503 Service Unavailable. The parser honours Expect: 100-continue and sends the interim 100 Continue once per request.

Chunked responses

Set is_chunked on the response to stream data, for example for server-sent events. The server then sends Transfer-Encoding: chunked instead of Content-Length.