Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would it be feasible/possible to add new event hook prior to request being made #2641

Closed
2 tasks done
levsoroka opened this issue Mar 18, 2024 · 4 comments
Closed
2 tasks done
Labels
feature request stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it

Comments

@levsoroka
Copy link

Prerequisites

Description

I am specifically interested in seeing if it is feasible to build additional event hook to fire off prior to request in locust being made. Inverse of this hook https://docs.locust.io/en/stable/api.html#locust.event.Events.request Available hook is fired when request is completed, this would fire prior to request being made.
In particular my use case is to be able modify request headers in bulk/conditionally. Has a request like this come in at all? Would this be feasible to build out.

@cyberw
Copy link
Collaborator

cyberw commented Mar 18, 2024

Hmm... I think what you want is just to wrap the calls in a subclass. See the subclasses at the end of this file for example:

class RestUserThatLooksAtErrors(FastHttpUser):

@levsoroka
Copy link
Author

Thank you. This surely helps with fasthttpuser class. Would there be equivalent way to
Wrap HttpUser class. I am having hard time figuring out which method can be used on the class tho pass in additional headers.

@cyberw
Copy link
Collaborator

cyberw commented Mar 21, 2024

If you just want to set default headers in HttpUser, you can try self.client.headers = {'user-agent': 'Mozilla/5.0 ...'} (havent tested it myself)

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
Projects
None yet
Development

No branches or pull requests

2 participants