ExMCP.HttpPlug.SSEConnection behaviour (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Connection operations ExMCP.HttpPlug.SSEHandler needs from its socket.

The handler used to sniff its conn at runtime (is_struct/1 plus Map.has_key?/2 checks for :chunk and :get_req_header function fields) so that tests could pass a fake connection. That put test-only branches in the production write path.

Instead the handler calls a connection module resolved once at start-up from the :conn_module key of its options, defaulting to ExMCP.HttpPlug.SSEConnection.PlugConn. Tests (or alternative adapters) supply their own implementation:

SSEHandler.start_link(fake_conn, session_id, %{conn_module: MyFakeConn})

Summary

Callbacks

Writes a chunk to the connection.

Reads a request header, returning a (possibly empty) list of values.

Functions

Resolves the connection module from handler options.

Types

conn()

@type conn() :: term()

Callbacks

chunk(conn, iodata)

@callback chunk(conn(), iodata()) :: {:ok, conn()} | {:error, term()}

Writes a chunk to the connection.

get_req_header(conn, t)

@callback get_req_header(conn(), String.t()) :: [String.t()]

Reads a request header, returning a (possibly empty) list of values.

Functions

resolve(opts)

@spec resolve(map() | keyword()) :: module()

Resolves the connection module from handler options.