# `MuroPlug.Adapter`
[🔗](https://github.com/murolang/muro_plug/blob/main/lib/muro_plug/adapter.ex#L1)

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.

# `t`

```elixir
@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()
}
```

# `upgrade`

`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}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
