-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Conversation
|
Great feature, thank you! I'm wondering, if every line is JSON, wouldn't that make the input file |
|
I'm also intrested in this feature. Would it be possible to implement a streaming reader? I was imagining using it with a JSONL file on the order of tens of GB, so reading the entire file at once would be very resource intensive |
|
Streaming (read 1 line into memory, not all lines) would be relatively easy, but you would have to rewrite this PR to not read everything upfront but on demand 😅 let file = File::open("bodies.txt")?;
let mut reader = BufReader::new(file);
for line_result in reader.lines() {
let line = line_result?; // Propagate I/O errors if they happen
} |
|
Yes, sure. I'm still new to Rust but I'd like to give it a shot. Any suggestions are very welcome 😄 |
|
If you want to try, you could checkout this PR and modify it to read line-by-line. But it could be easier to checkout master and copy only the lines you need from this PR because it hasn't been merged since April so it's 68 commits behind 😄 |
|
#787 any feedback would be greatly appreciated, if everything looks good I will mark it as ready for review |
|
I want to put all varying url/body/headers to |
Ok, I've aligned my PR |
|
Sorry for delayed response. I added the feature in this PR in #789. it slightly different because it picks random line not sequential though. Thank you for your PR! |
feat: Add option to read request body line-by-line from file. #729
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).