Skip to content

feat: Add option to read request body line-by-line from file. #729

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

K4YN5
Copy link

@K4YN5 K4YN5 commented Apr 15, 2025

Description: This PR introduces a new command-line option -Z to oha that allows reading request bodies line-by-line from a specified file.

Motivation: Needed to simulate different bodies to test my cache layer on my project.

Implementation: Adds a new command-line argument -Z (using clap). Also, made -D, -d and -Z incompatible from clap. When this argument is present, oha reads the specified file line by line. For each request made, the next line from the file is used as the request body. When the file ends, wraps around. Updated the README and command-line help text to include the new option.

Example Usage:
Assuming bodies.txt contains lines like {"url": "http://example.com/1"}, {"url": "http://example.com/2"}, etc.:
oha -n 10000 -c 100 -m POST -H "Content-Type: application/json" -Z bodies.txt http://target-endpoint/

Testing Done
Verified the functionality manually with a local server.
Ran the full test suite using cargo test.

Important Note on Test Failures:
During testing on my local machine, the tests test_google and test_proxy failed. These tests also fail consistently when running on the unmodified master branch in my environment, suggesting an environment problem not regarding my modifications.

All other tests in the suite pass successfully with these changes applied (verified using cargo test -- --skip test_google --skip test_proxy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant