Explorer reports addition
We have added a new Explorer feature to reports, with a timeline scrubber and easy anomaly detection.
How to set custom headers with your requests
LoadForge can record your browser, graphically build tests, scan your site with a wizard and more. Sign up now to run your first test.
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)
The examples below show two methods of setting headers. You can set any key-value headers you need with LoadForge.
Below we set our POST requests Content-Type to application/vnd.api+json and
the GET request to application/json within the same test.
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"})
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.
def on_start(self):
self.client.headers.update({'Authorization': 'Bearer xxx'})
def on_start(self):
self.client.headers.update({'Content-Type': 'application/json'})
Sometimes you need 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:
def on_start(self):
self.client.headers.update({'Host': 'www.loadforge.com'})
Or, on a single get/post request:
self.client.get("/api/test", headers={"Host": "www.loadforge.com"})
These are just partial examples from a test. You may use the wizard or another example template and copy paste these into your test.
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 to supercharge your testing!