package async_rpc_websocket

  1. Overview
  2. Docs

Module Rpc_websocket.RpcSource

Sourcemodule Connection_source : sig ... end
Sourcemodule Connection_initiated_from : sig ... end
Sourcetype http_handler = body:Cohttp_async.Body.t -> Async.Socket.Address.Inet.t -> Cohttp_async.Request.t -> Cohttp_async.Server.response Async.Deferred.t
Sourcetype raw_http_handler = body:Cohttp_async.Body.t -> Async.Socket.Address.Inet.t -> Cohttp_async.Request.t -> Cohttp_async.Server.response_action Async.Deferred.t
Sourcetype should_process_request = Async.Socket.Address.Inet.t -> (Cohttp.Header.t * [ `is_websocket_request of bool ]) Connection_source.t -> unit Core.Or_error.t
Sourcetype 'l tcp_server = (Async.Socket.Address.Inet.t, 'l) Async.Tcp.Server.t Async.Deferred.t
Sourcetype 'l ws_server = (Async.Socket.Address.Inet.t, 'l) Cohttp_async.Server.t Async.Deferred.t

There are a few parameters common to the functions below:

  • http_handler describes how to handle non-websocket HTTP requests. Defaults to always returning code 501, (for servers that are only serving web sockets and no other resources via HTTP)
  • should_process_request allows the user to deny access for a given request, before handling any RPCs, or serving web requests from a client
  • on_handshake_error defaults to `Ignore.
Sourceval handler : ?description:Core.Info.t -> implementations:'connection_state Async.Rpc.Implementations.t -> initial_connection_state: ('connection -> Connection_initiated_from.t -> Async.Socket.Address.Inet.t -> Async.Rpc.Connection.t -> 'connection_state) -> ?http_handler:('connection -> http_handler) -> ?handshake_timeout:Core.Time_float.Span.t -> ?heartbeat_config:Async.Rpc.Connection.Heartbeat_config.t -> ?should_process_request:should_process_request -> ?on_handshake_error: [ `Ignore | `Raise | `Call of Async.Socket.Address.Inet.t -> Core.Exn.t -> unit ] -> 'connection -> raw_http_handler

This returns a http handler that can be added into an existing cohttp server

Sourceval serve_with_tcp_server : where_to_listen_for_tcp: (Async.Socket.Address.Inet.t, 'l) Async.Tcp.Where_to_listen.t -> ?max_message_size:int -> ?make_transport:Async.Rpc.Connection.transport_maker -> where_to_listen:(Async.Socket.Address.Inet.t, 'l) Async.Tcp.Where_to_listen.t -> implementations:'s Async.Rpc.Implementations.t -> initial_connection_state: (unit -> Connection_initiated_from.t -> Async.Socket.Address.Inet.t -> Async.Rpc.Connection.t -> 's) -> ?http_handler:(unit -> http_handler) -> ?handshake_timeout:Core.Time_float.Span.t -> ?heartbeat_config:Async.Rpc.Connection.Heartbeat_config.t -> ?should_process_request:should_process_request -> ?on_handshake_error: [ `Ignore | `Raise | `Call of Async.Socket.Address.Inet.t -> Core.Exn.t -> unit ] -> ?on_handler_error: [ `Raise | `Ignore | `Call of Async.Socket.Address.Inet.t -> exn -> unit ] -> ?mode:Conduit_async.server -> ?backlog:int -> ?max_connections:int -> unit -> 'l tcp_server * 'l ws_server

Serves both HTTP/Websockets and regular RPCs via TCP server.

Sourceval serve : where_to_listen:(Async.Socket.Address.Inet.t, 'l) Async.Tcp.Where_to_listen.t -> implementations:'s Async.Rpc.Implementations.t -> initial_connection_state: (unit -> Connection_initiated_from.t -> Async.Socket.Address.Inet.t -> Async.Rpc.Connection.t -> 's) -> ?http_handler:(unit -> http_handler) -> ?handshake_timeout:Core.Time_float.Span.t -> ?heartbeat_config:Async.Rpc.Connection.Heartbeat_config.t -> ?should_process_request:should_process_request -> ?on_handshake_error: [ `Ignore | `Raise | `Call of Async.Socket.Address.Inet.t -> Core.Exn.t -> unit ] -> ?on_handler_error: [ `Raise | `Ignore | `Call of Async.Socket.Address.Inet.t -> exn -> unit ] -> ?mode:Conduit_async.server -> ?backlog:int -> ?max_connections:int -> unit -> 'l ws_server

Serves HTTP/Websockets only

Sourceval client : ?headers:Cohttp.Header.t -> ?handshake_timeout:Core.Time_ns.Span.t -> ?heartbeat_config:Async.Rpc.Connection.Heartbeat_config.t -> Uri.t -> Async.Rpc.Connection.t Async.Deferred.Or_error.t

Connect to a Websockets RPC server at the given URI.

Sourcemodule Transport : sig ... end

These functions are similar to the handler and server function in the parent module. The difference is that the caller of these functions is expected to construct (and also close) their own Rpc.Connection.t from the given transport (which will itself be closed after the callback returns).