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

A thin, total reading of the emitted `step.muro` (`MuroPlug.Step`).

The book decides every protocol fact of one HTTP/1.1 connection:
when a request is complete, where it ends, whether it keeps the
connection, which protocol status (400, 413, 414, 417, 431, 501) is
owed, when a `100 Continue` interim is owed, and how a handler
response is framed. This module only names the fields of the
book's `Out` and `St` products and feeds it facts. It does not make
protocol decisions of its own.

The buffer passed to the book is always a binary (`Slice` on the
BEAM). Nothing here builds a list of octets.

# `out`

```elixir
@type out() :: %{
  raw: tuple(),
  phase: non_neg_integer(),
  code: non_neg_integer(),
  close: 0 | 1,
  status_now: 0 | 1,
  read_more: 0 | 1,
  write_more: 0 | 1,
  span: non_neg_integer(),
  cover: 0 | 1,
  left: non_neg_integer(),
  wake: non_neg_integer(),
  keep: 0 | 1,
  hend: non_neg_integer(),
  te: non_neg_integer(),
  saw_cl: non_neg_integer(),
  cl: non_neg_integer()
}
```

The book's `Out` product, decoded by `out/1`.

# `st`

```elixir
@type st() :: tuple()
```

The book's `St`: `{:st, phase, code, left, keep, hend, te, sawCL, cl}`.

# `chunk_done?`

```elixir
@spec chunk_done?(out(), binary()) :: boolean()
```

True when the chunked body after `hend` is finished in `buf` (`ckDone`).

# `framed_end`

```elixir
@spec framed_end(out(), binary()) :: non_neg_integer()
```

First byte past the request this `Out` describes (`framedEndAt`).

# `hand`

```elixir
@spec hand(out(), keyword()) :: out()
```

Feed the handler's result to the book (`hand` in step.muro).

Returns the framing the book chose: span 2 is a buffered body,
3 a content-length pull (`send_file`), 4 chunked, 5 close-delimited;
`keep` 0 keeps the connection, 1 closes it.

# `out`

```elixir
@spec out(tuple()) :: out()
```

Decode the book's `Out` tuple into a map.

# `over_status`

```elixir
@spec over_status(out(), non_neg_integer()) :: out()
```

The protocol span a failed body read owes after a successful handler
(`overStatus` in step.muro): 400 or 413 owes that status and closes;
any other code is outside (`cover` 1), and the host shuts.

# `read_st`

```elixir
@spec read_st() :: st()
```

The book's initial read state.

# `step`

```elixir
@spec step(st(), atom(), binary(), map(), non_neg_integer(), non_neg_integer()) ::
  out()
```

Feed one fact to the book. `fact` is an atom; `buf` the unconsumed buffer.

The carried deadline is always 0, so the book arms `now + idle` on
each read. Thousand Island's `read_timeout` is that same idle budget
and delivers the NOW fact (`MuroPlug.Handler.handle_timeout/2`), so
the book's `wake` is not re-armed by the host.

# `take`

```elixir
@spec take(out()) :: st()
```

The book's `St` for an `Out` (`take` in step.muro).

# `views`

```elixir
@spec views(binary()) :: %{
  method: binary(),
  target: binary(),
  path: binary(),
  query: binary(),
  version: binary()
}
```

Request-line views over the buffer.

---

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