MuroPlug.Adapter (muro_plug v0.1.0)

Copy Markdown View Source

The Plug.Conn.Adapter for MuroPlug.

The payload is one request on one Thousand Island socket. Response framing is not decided here: every send_* call first asks the book (hand in step.muro, through MuroPlug.Book.hand/2) which span to write (2 buffered, 3 content-length pull, 4 chunked, 5 close-delimited) and whether the connection is kept. This module then renders exactly that.

Request and response bodies are binaries or iodata of binaries. A body is never a list of octets.

upgrade/3 takes a :websocket upgrade (WebSock), see MuroPlug.WebSocket.

Over TLS the same calls go through ThousandIsland.Transports.SSL. send_file/6 uses ThousandIsland.Socket.sendfile/4, which is the kernel's :file.sendfile on TCP and, on SSL, :file.pread of up to 1 MiB at a time written with :ssl.send, so a file body is the same bytes on either transport.

Summary

Functions

Plug.Conn.upgrade_adapter(conn, :websocket, {websock, state, opts}), the tuple WebSockAdapter.upgrade/4 passes to every server but Cowboy.

Types

t()

@type t() :: %MuroPlug.Adapter{
  body: term(),
  cfg: term(),
  head: term(),
  headers: term(),
  http11: term(),
  leftover: term(),
  method: term(),
  peer: term(),
  req: term(),
  resp: term(),
  sock: term(),
  socket: term(),
  upgrade: term()
}

Functions

upgrade(p, arg2, spec)

Plug.Conn.upgrade_adapter(conn, :websocket, {websock, state, opts}), the tuple WebSockAdapter.upgrade/4 passes to every server but Cowboy.

The request must be an RFC 6455 opening handshake (MuroPlug.WebSocket.check/3); if not, this raises MuroPlug.WebSocket.UpgradeError (400, or 426 for a version other than 13). Bad option values raise ArgumentError before anything is written. The spec is kept on the payload; after the Plug returns, MuroPlug.Handler writes the 101 and runs the WebSocket on this socket. Other protocols are {:error, :not_supported}.