Skip to content

feat(app): export request/response as HAR file#8484

Open
komen205 wants to merge 5 commits into
usebruno:mainfrom
komen205:feature/export-response-as-har
Open

feat(app): export request/response as HAR file#8484
komen205 wants to merge 5 commits into
usebruno:mainfrom
komen205:feature/export-response-as-har

Conversation

@komen205

@komen205 komen205 commented Jul 4, 2026

Copy link
Copy Markdown

Description

Closes #8485. Related to #1636 (HAR import), where export was also requested in the comments.

This PR adds an Export as HAR action to the response pane, letting users export the request/response pair of the last run as a HAR 1.2 file that can be opened in Chrome DevTools, Firefox, or any HAR viewer/tooling.

The export is built from item.requestSent and item.response, so the file reflects the request as it was actually sent — interpolated URL, resolved auth headers, and the serialized body — rather than the pre-interpolation template.

Changes:

  • bruno-app/src/utils/exporters/har.js — new buildHarLog() that converts requestSent + response into a HAR 1.2 log:
    • textual response bodies (JSON/XML/HTML/text/…) are embedded as text; binary bodies use encoding: "base64" per spec
    • multi-value headers (set-cookie) are flattened into separate HAR header entries
    • request/response cookies parsed into HAR cookie arrays; query string parsed from the final URL
    • covered by unit tests (har.spec.js, 8 cases)
  • bruno-app/src/components/ResponsePane/ResponseHarExport/ — new response-pane action component following the existing ResponseDownload pattern; wired into the actions row and the "more actions" dropdown for both HTTP and GraphQL requests. Disabled while a response is streaming or when the request failed without a response.
  • bruno-electron — new renderer:export-har-file IPC handler (mirrors renderer:save-response-to-file) that shows a save dialog defaulting to <request-name>.har and writes the prettified JSON.
image

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. ([Feature] Export request/response as HAR file #8485)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added an Export as HAR response action to the response toolbar with proper disabled-state handling.
    • Implemented HAR 1.2 file generation and save-to-disk flow via a user-selected location, with success/cancel/error feedback.
  • Bug Fixes

    • Improved HAR generation for headers, cookies, query strings, redirects, and correct handling of both text and binary response bodies.
  • Tests

    • Added Jest coverage validating HAR log structure, field mappings, and robustness for empty/missing request/response data.

Adds an 'Export as HAR' action to the response pane that exports the
request that was actually sent (item.requestSent) together with the
received response as a HAR 1.2 file.

- new buildHarLog() exporter in bruno-app utils (with jest specs)
- new ResponseHarExport response-pane action component
- new renderer:export-har-file ipc handler that prompts for a save
  location (defaults to <request-name>.har) and writes the file

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: c1288ca3-c5d8-41e4-bf53-793701e1b088

📥 Commits

Reviewing files that changed from the base of the PR and between 5eacb18 and f5fbb94.

📒 Files selected for processing (2)
  • packages/bruno-app/src/utils/exporters/har.js
  • packages/bruno-app/src/utils/exporters/har.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/utils/exporters/har.spec.js

Walkthrough

Adds HAR export for response data: a HAR builder, an Electron save handler, and a response-pane export control wired into the action menus.

Changes

HAR Export Feature

Layer / File(s) Summary
HAR log builder utility and tests
packages/bruno-app/src/utils/exporters/har.js, packages/bruno-app/src/utils/exporters/har.spec.js
Adds buildHarLog plus helpers for headers, query strings, cookies, request bodies, response content, redirect URLs, and timing fields, with Jest coverage for the output shape and mappings.
Electron IPC handler to save HAR file
packages/bruno-electron/src/ipc/network/index.js
Adds renderer:export-har-file to choose a destination, write the HAR JSON, and return success or cancellation status.
ResponseHarExport component
packages/bruno-app/src/components/ResponsePane/ResponseHarExport/index.js, .../StyledWrapper.js
Adds a forwardRef export control with disabled-state logic, imperative click()/isDisabled, toast-backed export handling, and styled rendering.
Wire export into ResponsePaneActions menus
packages/bruno-app/src/components/ResponsePane/ResponsePaneActions/index.js
Adds the HAR export entry to both menu variants, connects it to a ref, and renders the export control in the action bar.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ResponsePaneActions
  participant ResponseHarExport
  participant buildHarLog
  participant ElectronIPC
  participant FileSystem

  User->>ResponsePaneActions: Click "Export as HAR"
  ResponsePaneActions->>ResponseHarExport: ref.click()
  ResponseHarExport->>buildHarLog: buildHarLog({ requestSent, response })
  buildHarLog-->>ResponseHarExport: HAR log
  ResponseHarExport->>ElectronIPC: invoke('renderer:export-har-file', har, pathname)
  ElectronIPC->>FileSystem: chooseFileToSave + writeFile(JSON)
  FileSystem-->>ElectronIPC: filePath or cancelled
  ElectronIPC-->>ResponseHarExport: result
  ResponseHarExport-->>User: success or error toast
Loading

Suggested reviewers: helloanoop, lohit-bruno, bijin-bruno, sid-bruno

Poem

A HAR file blooms from request and reply,
With cookies and headers tucked neatly inside.
Click once to export, let the bytes take a flight,
And save every timing just so, and just right.

🚥 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 is concise and accurately summarizes the main change: exporting request/response data as a HAR file.
Linked Issues check ✅ Passed The PR implements the HAR export action, exporter, and IPC handler required by issue #8485, including faithful request data handling.
Out of Scope Changes check ✅ Passed The changes are focused on HAR export UI, export logic, tests, and file saving, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

komen205 and others added 2 commits July 4, 2026 20:01
- response.bodySize now reflects the transferred size (content-length
  header) instead of the decoded body length, falling back to -1
- redirectURL is only populated for 3xx responses
- document the httpVersion and timings approximations
- add tests for no-cookie requests and charset content types

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/bruno-app/src/components/ResponsePane/ResponseHarExport/index.js (1)

22-41: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Consider warning users that exported HAR includes raw credentials.

buildHarLog preserves resolved Authorization/Cookie headers verbatim (by design, per PR objective). HAR files are commonly shared with third parties (DevTools, support tickets, bug reports), so a leaked token/cookie is a realistic risk once this file leaves the user's machine. Consider a confirmation toast/dialog noting that the exported file contains sensitive headers, similar to how browsers warn on HAR export.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/ResponsePane/ResponseHarExport/index.js`
around lines 22 - 41, The HAR export flow in exportHarFile currently shows only
a success toast, but it should warn that the generated HAR contains raw
sensitive headers. Update the export path in exportHarFile to add a
confirmation/notice before or during the export, and include a clear warning
about Authorization/Cookie values being preserved by buildHarLog so users know
the file may expose credentials. Use the existing exportHarFile, buildHarLog,
and toast usage in ResponseHarExport to place the warning where the export is
triggered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/utils/exporters/har.js`:
- Around line 58-82: The HAR request builder is serializing binary request
bodies incorrectly because buildHarRequest uses requestSent.data and
JSON.stringify for non-string payloads. Update buildHarRequest to prefer
requestSent.dataBuffer when present, populate harRequest.postData from the raw
Buffer content, and keep the existing text/JSON fallback only for non-buffer
bodies. Make sure the change is localized to the postData construction logic in
buildHarRequest and still sets mimeType and bodySize correctly.

---

Nitpick comments:
In `@packages/bruno-app/src/components/ResponsePane/ResponseHarExport/index.js`:
- Around line 22-41: The HAR export flow in exportHarFile currently shows only a
success toast, but it should warn that the generated HAR contains raw sensitive
headers. Update the export path in exportHarFile to add a confirmation/notice
before or during the export, and include a clear warning about
Authorization/Cookie values being preserved by buildHarLog so users know the
file may expose credentials. Use the existing exportHarFile, buildHarLog, and
toast usage in ResponseHarExport to place the warning where the export is
triggered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ef69eaa3-afa9-4046-a038-204a9fbfc0e6

📥 Commits

Reviewing files that changed from the base of the PR and between b1f08b5 and 89a214c.

📒 Files selected for processing (6)
  • packages/bruno-app/src/components/ResponsePane/ResponseHarExport/StyledWrapper.js
  • packages/bruno-app/src/components/ResponsePane/ResponseHarExport/index.js
  • packages/bruno-app/src/components/ResponsePane/ResponsePaneActions/index.js
  • packages/bruno-app/src/utils/exporters/har.js
  • packages/bruno-app/src/utils/exporters/har.spec.js
  • packages/bruno-electron/src/ipc/network/index.js

Comment thread packages/bruno-app/src/utils/exporters/har.js
requestSent.data may be a parsed JSON object (parseDataFromResponse
JSON-parses request bodies), so re-stringifying it loses the original
body formatting. Prefer dataBuffer, which holds the exact bytes sent,
and keep the stringify path only as a fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Jul 4, 2026
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.

[Feature] Export request/response as HAR file

1 participant