add x-forwarded-for example

This commit is contained in:
Lars Holmberg 2024-10-09 14:39:02 +02:00
parent b13a047123
commit 9477459cd8
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
from locust import HttpUser, run_single_user, task
import random
class ForwardedForUser(HttpUser):
subnet = "10.10."
def __init__(self, environment):
super().__init__(environment)
self.fake_ip = self.subnet + str(random.randint(0, 254)) + "." + str(random.randint(0, 254))
self.client.headers["X-Forwarded-For"] = self.fake_ip
class WebsiteUser(ForwardedForUser):
@task
def index(self):
with self.client.get("/", catch_response=True) as resp:
pass
if __name__ == "__main__":
run_single_user(WebsiteUser)