Skip to content

HttpHost

Category: Acp

Source: http_host.dart

HTTP host for ACP over WebSocket.

Binds an HTTP server to a port, accepts WebSocket upgrades on configurable paths, and spawns one [AcpServer] per connection. All connections share the same [AcpServerDelegate] (so harness state like ServiceLocator initialization is reused), but each connection has its own per-connection session map inside that delegate's implementation.

Multi-tenancy isolation between connections is the delegate's responsibility — the host just hands each WS the JSON-RPC peer adapter.

Classes

AcpHttpHost

Binds an [HttpServer], handles WebSocket upgrades on [path], and runs an [AcpServer] for each connection.

Constructor

dart
AcpHttpHost({
    required this.delegateFactory,
    this.config = const AcpServerConfig(),
    this.path = '/acp',
    this.bearerToken,
  })

Properties

PropertyTypeDescription
configAcpServerConfig
pathStringHTTP path that accepts the WebSocket upgrade. Other paths return 404. * accepts any path.
bearerTokenString?When non-null, every WebSocket upgrade must present this token in either an Authorization: Bearer <token> header or a ?token=… query parameter. Required for non-loopback binds.
portint? getThe bound port (after [start]). Useful for tests that pass 0.
activeConnectionsint getNumber of currently-active WebSocket connections. Useful for tests + observability.
onConnectionClosedStream<void> getStream that fires every time a connection closes — useful for tests that want to await teardown.
diffvar
diffreturn
transportWebSocketTransport
serverAcpServer
portint? getThe bound port (after [start]). Useful for tests that pass 0.
activeConnectionsint getNumber of currently-active WebSocket connections. Useful for tests + observability.
onConnectionClosedStream<void> getStream that fires every time a connection closes — useful for tests that want to await teardown.

Methods

Future<int> start({InternetAddress? address, int port = 3000})

Bind the HTTP server. Returns the bound port. Pass [port]=0 to let the OS pick.

Future<void> stop()

Close the host. Existing connections are forcibly torn down.

Released under the MIT License.