> ## Documentation Index
> Fetch the complete documentation index at: https://docs.loadforge.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom HTTP Headers

> How to set custom headers with your requests

## Overview

You can easily set any headers you need by tweaking your get() or post() calls to include a header set.
This is commonly used for authentication on an API (see [api examples](rest-api))

The examples below show two methods of setting headers. You can set any key-value headers you
need with LoadForge.

## Code

Below we set our POST requests `Content-Type` to `application/vnd.api+json` and
the GET request to `application/json` within the same test.

```python theme={null}
self.client.post(
    "/login",
    data=json.dumps(payload),
    headers={"Content-Type": "application/vnd.api+json"}
)

self.client.get("/api/test", headers={"Content-Type": "application/json"})
```

## Global Headers

You can also set headers globally by defining the on\_start() section as shown below.
This will ensure ALL requests have the custom header added.

```python theme={null}
def on_start(self):
    self.client.headers.update({'Authorization': 'Bearer xxx'})
```

```python theme={null}
def on_start(self):
    self.client.headers.update({'Content-Type': 'application/json'})
```

## Custom Host Header

Sometimes you need to set a custom host header, for example if you are testing against an IP
address or a non-standard port. You can do this by setting the `Host` header:

```python theme={null}
def on_start(self):
    self.client.headers.update({'Host': 'www.loadforge.com'})
```

Or, on a single get/post request:

```python theme={null}
self.client.get("/api/test", headers={"Host": "www.loadforge.com"})
```

<Warning title="These are snippets!">
  These are just partial examples from a test. You may use the wizard or another example
  template and copy paste these into your test.
</Warning>

***

<Note title="Locust Test Example">
  LoadForge is powered by locust, meaning open source locust users can copy this script as well.
  If you are a locust user, consider importing your script to [LoadForge](https://loadforge.com) to supercharge your testing!
</Note>
