Skip to content

refactor: revert HeaderList method names to PropertyList conventions#7931

Merged
bijin-bruno merged 2 commits intousebruno:mainfrom
sanish-bruno:fix/reinstante-old-method-names
May 6, 2026
Merged

refactor: revert HeaderList method names to PropertyList conventions#7931
bijin-bruno merged 2 commits intousebruno:mainfrom
sanish-bruno:fix/reinstante-old-method-names

Conversation

@sanish-bruno
Copy link
Copy Markdown
Collaborator

@sanish-bruno sanish-bruno commented May 6, 2026

JIRA

Summary

Reverts HeaderList method names from MDN Headers naming (append, set, delete, forEach) back to PropertyList conventions (add, upsert, remove, each) for consistency with CookieList and the rest of the PropertyList hierarchy.

Method name reversions

Was (MDN) Now (PropertyList)
append(item | name, value?) add(item | name, value?)
set(item | name, value?) upsert(item | name, value?)
delete(predicate, context?) remove(predicate, context?)
forEach(fn, context?) each(fn, context?)

Two-arg form support on add() and upsert() is preserved.

Test plan

  • npm run test --workspace=packages/bruno-js — 488 tests pass
  • npm run test --workspace=packages/bruno-converters — 950 tests pass
  • Run E2E tests against .bru integration test files

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.

Summary by CodeRabbit

  • New Features

    • Request/response header API updated: new add(), upsert(), remove() methods and each() iterator replace prior write/iteration methods for clearer, consistent scripting.
  • Refactor

    • Translation layers updated to map legacy header operations to the new headerList surface and unify request/response handling.
  • Tests

    • Updated and expanded unit and integration tests to validate new header methods, iteration behavior, and read-only response semantics.

- Renamed methods in req.headerList and res.headerList from 'forEach' to 'each' for consistency with the new API.
- Updated method translations in the Postman converters to reflect the new method names: 'append' to 'add', 'set' to 'upsert', and 'delete' to 'remove'.
- Adjusted related tests to ensure they validate the new method names and functionality.
- Removed deprecated test cases for 'append' and 'set', replacing them with tests for 'add' and 'upsert'.
- Enhanced documentation to clarify the changes in method names and their usage.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Caution

Review failed

Failed to post review comments

Walkthrough

The PR refactors the HeaderList API: renames iteration forEacheach, replaces write methods append/set/delete with add/upsert/remove, and propagates these changes across Bruno core, QuickJS sandbox shims, Postman↔Bruno translators, autocomplete hints, and tests.

Changes

HeaderList API Refactor

Layer / File(s) Summary
Core Data & API
packages/bruno-js/src/header-list.js
Reworks HeaderList: adds add(itemOrName, value), replaces set with upsert(...), renames deleteremove(...), renames forEacheach(...), and routes populate/assimilate through new write APIs; preserves case-insensitive semantics and __headersToDelete bookkeeping.
VM Bridge & Runtime Wiring
packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js, packages/bruno-js/src/sandbox/quickjs/shims/bruno-response.js, packages/bruno-js/src/sandbox/quickjs/utils/property-list-bridge.js
Updates syncWriteMethods to include add, upsert, remove (remove append/set/delete); narrows iterator bridging to support remove predicate semantics; simplifies iterator eval (removes aliasing of forEach).
Converters (Bruno ↔ Postman)
packages/bruno-converters/src/postman/postman-translations.js, packages/bruno-converters/src/utils/bruno-to-postman-translator.js, packages/bruno-converters/src/utils/postman-to-bruno-translator.js
Updates translation mappings to use headerList namespace and new method names: map pm.request/response header iteration to req.headerList.each / res.headerList.each; replace append/set/delete translations with add/upsert/remove; map pm.request.headers.prepend/insert/insertAfter → req.headerList.add(...) (dropping positional semantics).
Editor Autocomplete
packages/bruno-app/src/utils/codemirror/autocomplete.js
Updates CodeMirror hints for req.headerList and res.headerList: adds each, add, upsert, remove; retains read helpers (find, filter, indexOf, map, reduce, toObject, toString, toJSON) and bulk ops (clear, populate, repopulate, assimilate) where applicable.
Unit & Integration Tests
packages/bruno-js/tests/header-list.spec.js, packages/bruno-converters/tests/*, packages/bruno-tests/collection/scripting/api/req/headerList/*, .../res/headerList/*
Replaces test usages of forEach/append/set/delete with each/add/upsert/remove; adds comprehensive tests for new write APIs, context-binding, case-insensitive behavior, response read-only enforcement; adds new add.bru and deletes append.bru.

Sequence Diagram(s)

sequenceDiagram
  participant Editor as CodeMirror Autocomplete
  participant Translator as Postman↔Bruno Translators
  participant Sandbox as QuickJS Sandbox Bridge
  participant HeaderList as Bruno HeaderList (core)
  Editor->>Translator: user script uses pm.request/pm.response headers
  Translator->>Sandbox: emit transformed calls (req.headerList.each/add/upsert/remove)
  Sandbox->>HeaderList: invoke `each` / `add` / `upsert` / `remove` (sync bridge)
  HeaderList-->>Sandbox: update req.headers & __headersToDelete
  HeaderList-->>Translator: (reads) header values for translation if needed
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • usebruno/bruno#7917: Overlaps on HeaderList API, shims, translators, and autocomplete changes.
  • usebruno/bruno#7673: Similar HeaderList refactor touching forEach → each and add/upsert/remove surface.
  • usebruno/bruno#7069: Related changes to request header scripting surface and translator mappings.

Suggested reviewers

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

Headers gather, case folded and clever,
each steps in—no loop lost forever;
add, upsert, remove take the stage,
scripts hum cleaner on Bruno's page. 🚀

🚥 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 refactoring: renaming HeaderList methods (forEach→each, append→add, set→upsert, delete→remove) to align with PropertyList conventions.
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.

@sanish-bruno sanish-bruno changed the title refactor: update headerList methods and translations for consistency refactor: revert HeaderList method names to PropertyList conventions May 6, 2026
- Introduced tests to verify that the 'idx' property is undefined in HeaderList, ensuring compliance with the updated API.
- Added tests to confirm that positional methods (prepend, insert, insertAfter) do not exist in HeaderList, reflecting the recent refactor.
- Implemented a test to check that the two-argument form of the 'add' method correctly overwrites existing headers, enhancing the robustness of header management tests.
@bijin-bruno bijin-bruno merged commit f8bf146 into usebruno:main May 6, 2026
12 checks passed
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.

2 participants