<!-- trunk-ignore-all(markdownlint/MD001) -->

<a href="https://arcjet.com" target="_arcjet-home">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
    <img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
  </picture>
</a>

# `@arcjet/headers`

<p>
  <a href="https://www.npmjs.com/package/@arcjet/headers">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fheaders?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
      <img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fheaders?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
    </picture>
  </a>
</p>

[Arcjet][arcjet] extension of the Headers class.

- [npm package (`@arcjet/headers`)](https://www.npmjs.com/package/@arcjet/headers)
- [GitHub source code (`headers/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/headers)

## What is this?

This is an internal utility to help us deal with [`Headers`][mdn-headers].
This exists to prevent the `cookie` header from being set and non-string values
from being set.

## When should I use this?

You should not use this but use `Headers` or plain objects instead.
This package matches our current needs which are likely different from yours.

## Install

This package is ESM only.
Install with npm in Node.js:

```sh
npm install @arcjet/headers
```

## Use

```ts
import { ArcjetHeaders } from "@arcjet/headers";

const headers = new ArcjetHeaders({ abc: "123" });

console.log(headers.get("abc")); // => "123"
```

## API

This package exports the identifier
[`ArcjetHeaders`][api-arcjet-headers].
The default export is [`ArcjetHeaders`][api-arcjet-headers].

This package exports no [TypeScript][] types.

### `new ArcjetHeaders([init])`

Creates a new `ArcjetHeaders` instance. We use this internally to prevent
the `cookie` header from being set and to ensure only string values are used.

###### Parameters

- `init` (`Headers | Array<[string, string]> | Record<string, Array<string> | string | undefined>`, optional)
  — initial headers to set

###### Returns

An `ArcjetHeaders` instance that extends the standard `Headers` class.

## License

[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]

[arcjet]: https://arcjet.com
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
[api-arcjet-headers]: #new-arcjetheadersinit
[mdn-headers]: https://developer.mozilla.org/en-US/docs/Web/API/Headers
[typescript]: https://www.typescriptlang.org/
