Skip to content

feat: add support for reading request body from file #108

Merged
11eshaannegi merged 5 commits into
mainfrom
feat/body-from-file
Mar 26, 2026
Merged

feat: add support for reading request body from file #108
11eshaannegi merged 5 commits into
mainfrom
feat/body-from-file

Conversation

@11eshaannegi

@11eshaannegi 11eshaannegi commented Mar 26, 2026

Copy link
Copy Markdown
Contributor
Screenshot 2026-03-26 091745

Adds support for reading the request body from a file using the -D (--body-file) flag. This simplifies handling large or complex payloads that are difficult to pass via CLI.


Changes

  • Added -D, --body-file <file_path> flag to read request body from a file
  • Integrated file input into existing request flow
  • Maintained compatibility with existing -b flag
  • Ensured mutual exclusion between -b and -D
  • Added validation for invalid or missing files

Usage

goperf run -m POST -D payload.json https://httpbin.org/post


Why

Previously, request bodies could only be passed using -b, which becomes inconvenient for large JSON payloads. This improves usability and supports real-world scenarios.


Testing

Screenshot 2026-03-26 092749
  • Tested with sample JSON file (`payload.json`)
  • Verified correct request body is sent

@rajat-tomar rajat-tomar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutual exclusion check and error wrapping are good but three things to address:

  1. Config file merge is incomplete — see inline comment on configfile.go
  2. Needs tests. config_test.go already has a table-driven Validate suite with the validConfig() helper. Add cases for: both -b and -D set (should error), nonexistent file (should error), valid file (Body should be populated after Validate)
  3. Fix the usage example in this PR description — goperf.exe run -- POST -D payload.json won't work. The -- means end-of-flags, so POST becomes the URL argument. Should be: goperf run -m POST -D payload.json https://httpbin.org/post

Comment thread cmd/configfile.go
Comment thread cmd/run.go Outdated
@11eshaannegi 11eshaannegi merged commit 83e054b into main Mar 26, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants