Skip to content

fix: preserve stream-backed file bodies during request interpolation - #7690

Merged
sid-bruno merged 2 commits into
usebruno:fix/7642-stream-files-internalfrom
hriztam:fix/7642
May 7, 2026
Merged

sid-bruno merged 2 commits into
usebruno:fix/7642-stream-files-internalfrom
hriztam:fix/7642

Conversation

@hriztam

@hriztam hriztam commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Address #7624
Fixes a bug where File / Binary request bodies stopped sending the file contents once the selected file crossed the large-file streaming threshold.

For small files, Bruno read the body as a Buffer and sent it correctly. For larger files, Bruno switched to fs.ReadStream, and the interpolation layer incorrectly treated that stream like a JSON object, causing the request body to become the stream’s internal fields instead of the file contents.

Root Cause

The request preparation path intentionally streams large files to avoid loading them fully into memory. Later, the interpolation logic only excluded Buffer payloads from JSON interpolation. Large file bodies were ReadStream instances, so they fell into the JSON interpolation branch and got serialized.

This change updates the interpolation guard in both Electron and CLI to treat readable streams as binary request bodies, just like buffers.

Changes

  • Preserve stream-backed file bodies during request interpolation in Electron
  • Preserve stream-backed file bodies during request interpolation in CLI
  • Add regression tests for stream-backed JSON file body requests

Testing

Passed:

  • node --experimental-vm-modules ../../node_modules/.bin/jest --runInBand tests/network/interpolate-vars.spec.js in packages/bruno-electron
  • node --experimental-vm-modules ../../node_modules/.bin/jest --runInBand tests/runner/interpolate-vars.spec.js tests/runner/prepare-request.spec.js in packages/bruno-cli

Manual UI Verification

  1. Start Bruno in dev mode.
  2. Create a POST request to a local echo server.
  3. Set Body to File / Binary with application/json.
  4. Send a small JSON file and a large JSON file (>20 MiB).
  5. Confirm both requests send actual file contents, and the large file no longer arrives as a serialized stream object like {"fd":null,"path":...}.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented JSON interpolation from modifying stream-like or binary request bodies, preserving original payloads.
  • Tests

    • Added tests to ensure stream-backed JSON payloads and file/body streaming scenarios preserve original data during interpolation.

Treat readable streams as binary request bodies in CLI and Electron
so large file uploads are not serialized during JSON interpolation.
Add regression coverage for stream-backed file body requests.
@coderabbitai

coderabbitai Bot commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60b6fb97-2a5d-484f-b580-7231174de19d

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf869f and ad7fbbb.

📒 Files selected for processing (3)
  • packages/bruno-cli/src/runner/interpolate-vars.js
  • packages/bruno-cli/tests/runner/interpolate-vars.spec.js
  • packages/bruno-electron/src/ipc/network/interpolate-vars.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/bruno-cli/tests/runner/interpolate-vars.spec.js
  • packages/bruno-cli/src/runner/interpolate-vars.js
  • packages/bruno-electron/src/ipc/network/interpolate-vars.js

Walkthrough

Introduces an isBinaryRequestBody helper in CLI and Electron interpolate-vars modules to detect Buffer or stream-like bodies, and updates the JSON-content interpolation guard to skip interpolation for any binary/stream-like payloads. Adds tests to assert stream-backed request bodies remain unmodified.

Changes

Binary/stream body interpolation guard

Layer / File(s) Summary
Detection helper
packages/bruno-cli/src/runner/interpolate-vars.js, packages/bruno-electron/src/ipc/network/interpolate-vars.js
Add local isBinaryRequestBody(data) that returns true for Buffer or stream-like objects (presence of .pipe).
Interpolation logic
packages/bruno-cli/src/runner/interpolate-vars.js, packages/bruno-electron/src/ipc/network/interpolate-vars.js
Replace Buffer.isBuffer(request.data) guard with isBinaryRequestBody(request.data) in the non-GraphQL JSON branch so binary/stream-like bodies skip JSON stringification/interpolation.
Tests
packages/bruno-cli/tests/runner/interpolate-vars.spec.js, packages/bruno-electron/tests/network/interpolate-vars.spec.js
Add tests asserting that stream-backed JSON/file-mode request bodies (mocked .pipe and path) are returned intact (same object reference) and not interpolated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • usebruno/bruno#6922: Generalizes Buffer-only guard to include stream-like payloads; closely related to the helper introduced here.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno
  • sid-bruno

Poem

🌊 Streams now slip through without a splice,
Buffers and pipes heed the same device,
Interpolation steps aside,
Keeping streamed bodies bona fide. 📦

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding logic to preserve stream-backed file bodies during request interpolation, which directly addresses the bug described in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/bruno-cli/tests/runner/interpolate-vars.spec.js (1)

1-21: Consider importing jest from @jest/globals for consistency.

Line 1 explicitly imports describe, it, expect from @jest/globals, but line 7 uses the global jest.fn(). While this works fine (Jest provides jest globally), adding jest to the import would be more consistent with the explicit import pattern already established.

♻️ Optional fix
-const { describe, it, expect } = require('@jest/globals');
+const { describe, it, expect, jest } = require('@jest/globals');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/tests/runner/interpolate-vars.spec.js` around lines 1 -
21, The test uses the global jest.fn() but the top imports already pull other
helpers from `@jest/globals`; update the import to also bring in jest from
'@jest/globals' so the file uses the same explicit import pattern, then ensure
the test continues to call jest.fn() (no other changes to interpolateVars or the
test logic are needed).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-cli/tests/runner/interpolate-vars.spec.js`:
- Around line 1-21: The test uses the global jest.fn() but the top imports
already pull other helpers from `@jest/globals`; update the import to also bring
in jest from '@jest/globals' so the file uses the same explicit import pattern,
then ensure the test continues to call jest.fn() (no other changes to
interpolateVars or the test logic are needed).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f9fc3840-1cfe-4966-96ad-4d137acb70c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4d6032b and 9bf869f.

📒 Files selected for processing (4)
  • packages/bruno-cli/src/runner/interpolate-vars.js
  • packages/bruno-cli/tests/runner/interpolate-vars.spec.js
  • packages/bruno-electron/src/ipc/network/interpolate-vars.js
  • packages/bruno-electron/tests/network/interpolate-vars.spec.js

@sid-bruno
sid-bruno self-requested a review as a code owner May 7, 2026 06:04
@sid-bruno
sid-bruno changed the base branch from main to fix/7642-stream-files-internal May 7, 2026 06:09
@sid-bruno sid-bruno added adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers labels May 7, 2026
@sid-bruno
sid-bruno merged commit 975c638 into usebruno:fix/7642-stream-files-internal May 7, 2026
9 of 10 checks passed
@sid-bruno

Copy link
Copy Markdown
Collaborator

Merged in to be polished by the maintainers

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

Labels

adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants