# HTTP

> The HTTP check - URL, method, redirects, headers, secret headers, body, the slow-response threshold, and what counts as success.

An HTTP check sends one request and judges the response: by default any 2xx or 3xx status passes; [assertions](https://docs.monitorly.cloud/checks/assertions.md) can require more.

```json
{
  "type": "http",
  "url": "https://api.example.com/health",
  "method": "GET",
  "maxRedirects": 5,
  "headers": [
    { "name": "Accept", "value": { "kind": "plain", "value": "application/json" } },
    { "name": "Authorization", "value": { "kind": "secret", "value": "Bearer <token>" } }
  ],
  "degradedAfterMs": 1500,
  "assertions": [
    { "target": "status", "op": "eq", "value": 200 },
    { "target": "json", "path": "$.status", "op": "equals", "value": "ok" }
  ]
}
```

## Fields

| Field             | Type    | Default  | Rules                                                                                                      |
| ----------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| `url`             | string  | required | `http://` or `https://`, up to 2 KiB                                                                       |
| `method`          | string  | required | `GET`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE` or `OPTIONS`                                               |
| `maxRedirects`    | integer | required | 0 to 5. Each redirect is followed only to `http` or `https`, and its address is checked like the first one |
| `headers`         | array   | `[]`     | Up to 30 headers, below                                                                                    |
| `body`            | string  | none     | Up to 64 KiB, sent as is                                                                                   |
| `degradedAfterMs` | integer | none     | Shorter than the check's timeout. A response slower than this on a quorum makes the check DEGRADED         |
| `assertions`      | array   | `[]`     | Up to 20, see [HTTP assertions](https://docs.monitorly.cloud/checks/assertions.md)                                                       |

## Headers

Each header is `{"name": …, "value": …}`.

- `name`: an HTTP field name (RFC 9110 token), up to 256 bytes.
- `value`: either `{"kind": "plain", "value": "<text>"}`, up to 4 KiB, or a **secret**: `{"kind": "secret", "value": "<text>"}` to set it, `{"kind": "secret", "secretId": "<id>"}` to keep the stored one.

A secret value is encrypted at rest and never returned: responses carry only its `secretId`, and `monitorly export` writes `secret: keep`. It is decrypted only to send the request. A node that cannot read it ends the run without an outcome (`config.secret_unreadable`), not as DOWN.

A stored secret goes only to the origin and the header it was entered for. Changing the URL's scheme, host or port, or moving the secret to a header with another name, needs the value again: keeping it answers 422 `check.secret_host_changed` on that header.

Every request carries `User-Agent: Monitorly/<version> (+https://monitorly.cloud)` unless you set your own.

## Redirects

Redirects are followed one hop at a time, up to `maxRedirects`, and every hop's address is checked against the [node's address rules](https://docs.monitorly.cloud/concepts/nodes.md#what-platform-nodes-may-not-reach). 303, and 301 or 302 after a POST, continue as GET without a body; 307 and 308 keep the method and body.

When a redirect leads to another origin, only `Accept`, `Accept-Language`, `Cache-Control`, `Content-Language`, `Content-Type`, `Pragma` and `User-Agent` go on, and only with plain values. `Authorization`, cookies, API keys and every secret header stay with the origin the check names.

## The response

- The body is read up to 1 MiB; body and JSON assertions see that much.
- The run records the status code, the total time and its parts (DNS, connect, TLS, first byte) where they apply, the address it connected to, every redirect followed, the body size, and a few headers of the final response (`server`, `content-type`, `cache-control`, `x-request-id`, `cf-ray`).
- For an `https` URL the certificate must be valid and match the host. Certificate expiry warnings in advance are the job of an [SSL check](https://docs.monitorly.cloud/checks/ssl.md).

## Success

Without a `status` assertion, a run passes on any 2xx or 3xx status after redirects. With assertions, every assertion must hold. Each failed assertion is shown on the run with what was expected and what came back.

A run that never gets a response fails with a code such as `dns.nxdomain`, `tcp.refused`, `tls.expired` or `timeout`; see [Run results and error codes](https://docs.monitorly.cloud/checks/results.md).
