# `Ankusa.Http`
[🔗](https://github.com/jamescarr/ankusa/blob/ankusa-v0.7.0/packages/ankusa/lib/ankusa/http.ex#L1)

Small `Plug.Conn` helpers shared by every Bandit-fronted router in the
framework (`Ankusa.Edge.Router`, `Ankusa.ClaimCheck.Router`). Kept here
instead of duplicated so both surfaces enforce request bodies identically.

# `read_opts`

```elixir
@type read_opts() :: [read_timeout: pos_integer(), deadline: pos_integer()]
```

Limits on how long reading a body may take, both in milliseconds. Absent keys
leave Bandit's own per-read timeout (15 s) and no overall deadline.

  * `:read_timeout` — one socket read of the body must complete within this
    (`listener.body_read_timeout_ms`)
  * `:deadline` — the whole body must have arrived this long after the read
    started (`listener.request_deadline_ms`)

# `read_body_limited`

```elixir
@spec read_body_limited(Plug.Conn.t(), pos_integer(), read_opts()) ::
  {:ok, binary(), Plug.Conn.t()}
  | {:too_large, Plug.Conn.t()}
  | {:error, term(), Plug.Conn.t()}
```

Read the body, refusing anything over `max` bytes without buffering it all.

`{:too_large, conn}` is a body that exceeded the limit; `{:error, reason, conn}`
is one that could not be read at all (client disconnect, read timeout, or
`:request_deadline` when the body had not arrived within `:deadline`). Those
are different failures and are reported as such — folding a dropped connection
into "payload too large" tells the caller to shrink a body that was never the
problem.

A body that arrives in one read (every ordinary webhook) is returned as the
binary the transport produced, uncopied.

# `read_opts`

```elixir
@spec read_opts(Ankusa.Config.t()) :: read_opts()
```

The `read_body_limited/3` options `config.listener` asks for.

# `send_json`

```elixir
@spec send_json(Plug.Conn.t(), pos_integer(), map()) :: Plug.Conn.t()
```

Send a JSON-encoded response body with the given status.

---

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