# `VulnCheck.HTTP`
[🔗](https://github.com/Voskan/vulncheck/blob/v1.0.1/lib/vulncheck/http.ex#L1)

Minimal, hardened HTTP client built on `:httpc` and `:ssl`.

  * `https://` requests always verify the peer certificate against the
    operating system trust store (`:public_key.cacerts_get/0`) and check the
    hostname.
  * Plain `http://` is only allowed for loopback hosts (local test servers).
  * Successful responses are streamed with backpressure and aborted beyond
    `:max_body_bytes` (default 50 MiB). For other responses, `:httpc` delivers
    the buffered body before the client can check its size.
  * Partial responses are rejected because feed requests require a complete body.
  * Transient failures (`502`, `503`, `504`, timeouts, closed sockets) are
    retried up to two times with jitter.
  * Redirects are followed manually (at most 3) so every hop is validated.

The module implements the `VulnCheck.HTTP` behaviour itself; tests and
embedders can pass any other implementation through the `:http_client`
option accepted by the feed modules.

# `response`

```elixir
@type response() :: %{
  status: non_neg_integer(),
  headers: %{required(String.t()) =&gt; String.t()},
  body: binary()
}
```

# `get`

```elixir
@callback get(url :: String.t(), headers :: [{String.t(), String.t()}], opts :: keyword()) ::
  {:ok, response()} | {:error, term()}
```

# `get`

```elixir
@spec get(String.t(), [{String.t(), String.t()}], keyword()) ::
  {:ok, response()} | {:error, term()}
```

Performs a GET request.

Options: `:timeout`, `:connect_timeout`, `:max_body_bytes`, `:retries`
(default 2), `:retry_delay_ms` (default 300) and `:cacerts` (trusted DER
certificates, defaults to the operating system trust store).

# `ssl_options`

```elixir
@spec ssl_options(keyword()) :: keyword()
```

TLS options used for `https://` requests.

# `user_agent`

```elixir
@spec user_agent() :: String.t()
```

The `User-Agent` header value sent with every request.

# `validate_url`

```elixir
@spec validate_url(String.t()) :: :ok | {:error, term()}
```

Validates that a URL may be requested: `https://` anywhere, `http://` only
on loopback hosts.

---

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