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

The Thousand Island handler that drives the emitted `step.muro`.

Each socket event is one book fact: accept, bytes, wrote, now. The
book's `Out` says what to do next and the handler does only that:

  * read more (book phases 0, 4, 7),
  * write an owed protocol status and close (phase 1: 400, 413, 414,
    417, 431, 501, or a `status_now` close),
  * write the `100 Continue` interim (span 6) and feed the wrote back,
  * serve a finished request through the Plug (phase 3, span 2),
    then feed the wrote so the book either closes, idles, or
    classifies a pipelined tail in the same step,
  * close (phases 2 and 5, or `cover`).

The receive buffer is one binary. Request views, framing ends and
header-block ends all come from the book.

A Plug that upgrades to WebSocket (`Plug.Conn.upgrade_adapter/3`
with `:websocket`, e.g. through `WebSockAdapter.upgrade/4`) leaves the
book here: once the Plug returns, the handler writes the
`101 Switching Protocols` and the connection becomes a
`MuroPlug.WebSocket.Connection`. Any bytes after the upgrade request
are its first frame bytes. Process messages go to the `WebSock`
module's `handle_info/2`.

The handler is the same over TCP and TLS: Thousand Island finishes
the TLS handshake before `handle_connection/2`, and every read and
write goes through `ThousandIsland.Socket`. The scheme (`"http"` or
`"https"`) comes from `MuroPlug`'s options.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

```elixir
@spec start_link({handler_options :: term(), GenServer.options()}) ::
  GenServer.on_start()
```

---

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