feat: Add option to read request body line-by-line from file. #729
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).