# `HttpDouble.PlugAdapter`
[🔗](https://github.com/aszymanskiit/http_double/blob/main/lib/http_double/plug_adapter.ex#L1)

Converts between Plug.Conn and HttpDouble.Request/response_spec.

Used when HttpDouble runs on Plug.Cowboy: the Plug forwards every request
to the Server, which returns a response_spec; this module turns that into
a Plug.Conn response.

# `conn_to_request`

```elixir
@spec conn_to_request(Plug.Conn.t(), binary(), non_neg_integer(), non_neg_integer()) ::
  HttpDouble.Request.t()
```

Builds an HttpDouble.Request from a Plug.Conn (after body has been read).

`conn_id` and `request_index` should be set by the caller (Server).

# `response_spec_to_conn`

```elixir
@spec response_spec_to_conn(Plug.Conn.t(), HttpDouble.response_spec()) ::
  Plug.Conn.t()
```

Sends the response_spec back through the Plug.Conn.

Supports: map/struct (status, body, json, headers), `{:delay, ms, inner}`, `{:raw,
iodata}`, and `{:partial, [iodata]}` (chunks concatenated into one response body).

`:timeout` returns 504 after delay. `:close` terminates the request process to emulate
abrupt connection drop (no valid HTTP response). Route matches may pass `{spec,
route_id}` with a reference `route_id`; that tuple is unwrapped before handling.

Other unsupported specs fall back to a 200 empty body (with a log warning).

---

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