Locust passing headers

Liam Douglas picture Liam Douglas · Aug 24, 2018 · Viewed 11.1k times · Source

Is it possible to have Locust pass a header command with a secure token to load test an API?

I am trying to test our api for an encoder with a header flag for a token as the server being tested has to receive a token with the request, ie.

curl -H “Authorization: Token token string” http://someserver

Answer

Matt Doyle picture Matt Doyle · Mar 4, 2019

Yes, you can use:

token_string = "token string"

resp = self.client.post(
            url="http://someserver",
            data=json.dumps(data),
            auth=None,
            headers={"authorization": "Token " + token_string},
            name="http://someserver",
        )