Repository navigation
feat: add PropertyList API for req.headers and res.headers - #7673
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughIntroduces ChangesHeaderList Header Abstraction & Integration
Sequence DiagramsequenceDiagram
participant User as User Script
participant Req as BrunoRequest
participant HL as HeaderList
participant RawHdrs as req.headers
participant DH as req.disabledHeaders
User->>Req: new BrunoRequest(config)
Req->>HL: new HeaderList(this)
HL->>RawHdrs: read headers from config
HL->>DH: read disabledHeaders from config
User->>HL: upsert({ key, value })
HL->>HL: `#ciEquals`() for case-insensitive lookup
HL->>RawHdrs: update headers[key]
HL->>DH: remove matching disabled entry if exists
User->>HL: remove(predicate)
HL->>HL: filter all() with predicate
HL->>RawHdrs: delete matching headers
HL->>DH: remove matching disabled headers
User->>HL: populate(items)
HL->>HL: clear() first
HL->>RawHdrs: add new headers
User->>HL: get(name)
HL->>HL: case-insensitive lookup via all()
HL-->>User: return matching value or undefined
User->>HL: toObject()
HL->>HL: iterate all() with optional filtering
HL-->>User: return { key: value } map
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-js/src/bruno-response.js (1)
15-23: Minor redundancy: double null-guard onrawHeaders.Line 17 already defaults
rawHeadersto{}whenresis falsy, so the|| {}on line 21 is unnecessary.🔧 Suggested simplification
const headersList = new ReadOnlyPropertyList({ keyProperty: 'key', valueProperty: 'value', - items: Object.entries(rawHeaders || {}).map(([key, value]) => ({ key, value })) + items: Object.entries(rawHeaders).map(([key, value]) => ({ key, value })) }); - this._headersList = createHeadersProxy(headersList, rawHeaders || {}); + this._headersList = createHeadersProxy(headersList, rawHeaders);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-js/src/bruno-response.js` around lines 15 - 23, The code double-null-guards rawHeaders when building headersList and passing to createHeadersProxy; since rawHeaders is already set to res ? res.headers : {} use rawHeaders (not rawHeaders || {}) in the ReadOnlyPropertyList.items mapping and the createHeadersProxy call; update the references around ReadOnlyPropertyList instantiation and the createHeadersProxy(this._headersList, ...) call so they pass the single rawHeaders variable, keeping symbols headersList, ReadOnlyPropertyList, createHeadersProxy and rawHeaders intact.
🤖 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-js/src/bruno-response.js`:
- Around line 15-23: The code double-null-guards rawHeaders when building
headersList and passing to createHeadersProxy; since rawHeaders is already set
to res ? res.headers : {} use rawHeaders (not rawHeaders || {}) in the
ReadOnlyPropertyList.items mapping and the createHeadersProxy call; update the
references around ReadOnlyPropertyList instantiation and the
createHeadersProxy(this._headersList, ...) call so they pass the single
rawHeaders variable, keeping symbols headersList, ReadOnlyPropertyList,
createHeadersProxy and rawHeaders intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 26689fb4-8708-4bc8-a595-8070201b4484
📒 Files selected for processing (8)
packages/bruno-js/src/bruno-request.jspackages/bruno-js/src/bruno-response.jspackages/bruno-js/src/header-list.jspackages/bruno-js/src/headers-proxy.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-request.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-response.jspackages/bruno-js/src/sandbox/quickjs/utils/property-list-bridge.jspackages/bruno-js/tests/header-list.spec.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-js/src/header-list.js (1)
148-151: Consider validating or coercingitem.value.Currently,
upsert()allowsitem.valueto beundefinedor any type. IfsetHeaderexpects a string, you might want to coerce or validate:this._brunoRequest.setHeader(item.key, item.value ?? '');Alternatively, if allowing undefined is intentional (e.g., to clear a header), a brief comment would clarify intent.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-js/src/header-list.js` around lines 148 - 151, The upsert method currently passes item.value through unchecked to this._brunoRequest.setHeader which may expect a string; update upsert (function upsert) to validate/coerce item.value before calling this._brunoRequest.setHeader (e.g., convert non-string values to String(item.value) or use item.value ?? '' to default undefined/null to an empty string) and add a short comment explaining the chosen behavior (or explicitly allow undefined to mean header removal) so intent is clear.
🤖 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-js/src/header-list.js`:
- Around line 148-151: The upsert method currently passes item.value through
unchecked to this._brunoRequest.setHeader which may expect a string; update
upsert (function upsert) to validate/coerce item.value before calling
this._brunoRequest.setHeader (e.g., convert non-string values to
String(item.value) or use item.value ?? '' to default undefined/null to an empty
string) and add a short comment explaining the chosen behavior (or explicitly
allow undefined to mean header removal) so intent is clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0f8ece14-f41a-4b0f-806c-aa340feb39df
📒 Files selected for processing (3)
packages/bruno-js/src/header-list.jspackages/bruno-js/src/headers-proxy.jspackages/bruno-js/tests/header-list.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/bruno-js/src/headers-proxy.js
- packages/bruno-js/tests/header-list.spec.js
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-js/src/headers-proxy.js`:
- Around line 69-83: The headers proxy currently falls back to direct mutation
in createHeadersProxy's set and deleteProperty traps (referencing onSet,
onDelete, getRawHeaders), so add a readOnly boolean option to createHeadersProxy
and, when readOnly is true (pass readOnly: true from bruno-response.js where
response headers are created), have set and deleteProperty simply return false
instead of assigning/deleting; when readOnly is false preserve the existing
behavior (call onSet/onDelete if provided else mutate getRawHeaders()) so
callers can opt into immutable response headers.
- Around line 52-53: The proxy traps dereference getRawHeaders() (the getter
passed as () => brunoRequest.req.headers) without guarding against
null/undefined, while setHeaders(headers) can set a falsy value; update every
proxy trap that calls getRawHeaders() (e.g., the get trap used to return
getRawHeaders()[prop], plus other traps handling property access/mutation) to
first obtain const raw = getRawHeaders() and guard with raw || {} (or return
undefined for get) before dereferencing, so operations like get, set, has,
deleteProperty, and ownKeys behave safely when headers are null/undefined;
ensure the behavior matches PropertyList's dataSource fallback semantics.
🪄 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: aacbd9a6-7d8e-4ff5-b31a-db8707d58cf7
📒 Files selected for processing (3)
packages/bruno-js/src/headers-proxy.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-request.jspackages/bruno-js/src/sandbox/quickjs/utils/property-list-bridge.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-converters/tests/bruno/bruno-to-postman-translations/request.test.js`:
- Around line 233-281: The test suite only covers req.headerList.* translations;
add equivalent tests for the newly exposed req.headers API to ensure parity
(e.g., methods one, find, toObject, upsert plus
get/has/all/filter/add/remove/clear/standalone access). In the tests file
containing the existing cases (the tests invoking translateBruToPostman and
assertions like 'const ct = req.headerList.get("Content-Type");'), duplicate
representative specs but replace req.headerList with req.headers and include new
assertions for req.headers.one(...), req.headers.find(...),
req.headers.toObject(), and req.headers.upsert({...}) using the same
translateBruToPostman and expect pattern to assert they map to
pm.request.headers.* equivalents; keep naming consistent with existing it(...)
descriptions so CI/test reporting is clear.
🪄 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: 9f538308-608d-4554-8680-7f07c9ebd698
📒 Files selected for processing (13)
packages/bruno-converters/src/utils/bruno-to-postman-translator.jspackages/bruno-converters/src/utils/postman-to-bruno-translator.jspackages/bruno-converters/tests/bruno/bruno-to-postman-translations/request.test.jspackages/bruno-converters/tests/bruno/bruno-to-postman-translations/response.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/legacy-tests-syntax.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/request.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.jspackages/bruno-js/src/bruno-request.jspackages/bruno-js/src/bruno-response.jspackages/bruno-js/src/header-list.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-request.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-response.jspackages/bruno-js/tests/header-list.spec.js
✅ Files skipped from review due to trivial changes (1)
- packages/bruno-js/tests/header-list.spec.js
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/bruno-js/src/bruno-request.js
- packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js
- packages/bruno-js/src/bruno-response.js
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/bruno-js/src/bruno-request.js (2)
21-21:⚠️ Potential issue | 🟠 Major
this.headerscan drift fromthis.req.headersaftersetHeaders().Constructor captures
this.headers = req.headers(a reference).setHeaders(headers)reassigns onlythis.req.headers, so the publicreq.headersshorthand documented on Line 8 keeps pointing at the old object. Subsequent reads viareq.headers[...]orObject.keys(req.headers)in user scripts will silently observe stale data, andheaderList(constructed withthis) will read throughthis.req.headers— i.e. the new object — so the two APIs will disagree.🛠️ Suggested fix
setHeaders(headers) { this.req.headers = headers; + this.headers = headers; }Same concern technically applies to
setHeader/deleteHeader, but those mutate in place so the shared reference still works — only full reassignment breaks it.Also applies to: 131-133
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-js/src/bruno-request.js` at line 21, The constructor currently does this.headers = req.headers which creates a stale reference when setHeaders(headers) reassigns this.req.headers; fix by making the public shorthand always reflect the current request headers — either convert headers into a getter that returns this.req.headers (so headerList and external reads always see the live object) or ensure setHeaders(headers) also updates this.headers to point at the new object; apply the same fix/consistency to the other places noted (e.g., the code around setHeader/deleteHeader and the block at lines ~131-133) so no API surface can drift from this.req.headers.
101-120:⚠️ Potential issue | 🟡 MinorAdd case-insensitive header lookup to
getAuthMode()for consistency.
getAuthMode()checksheaders?.['Authorization']andheaders?.['X-WSSE']with exact casing, but the same file'shasJSONContentType()(line 164) checks both'Content-Type'and'content-type'to handle case variations. Since users can set headers with any casing viareq.setHeader(name, value), add a fallback to lowercase lookups:} else if (headers?.['Authorization']?.startsWith('Bearer') || headers?.['authorization']?.startsWith('Bearer')) { return 'bearer'; } else if (headers?.['Authorization']?.startsWith('Basic') || headers?.['authorization']?.startsWith('Basic') || this.req?.auth?.username) { return 'basic';Apply the same pattern to
X-WSSE.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-js/src/bruno-request.js` around lines 101 - 120, Update getAuthMode() to perform case-insensitive header checks for Authorization and X-WSSE like hasJSONContentType() does: when checking for bearer/basic auth and WSSE, also consult headers['authorization'] and headers['x-wsse'] fallbacks (in addition to headers['Authorization'] and headers['X-WSSE']) so startsWith('Bearer')/startsWith('Basic')/presence checks work regardless of header casing; modify the branches in getAuthMode() accordingly (preserving existing checks on this.req.oauth2, oauth1config, auth.username, awsv4, digestConfig) so behavior is identical but tolerant to header case variations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-js/src/bruno-response.js`:
- Line 10: The constructor sets this.headers = res ? res.headers : {} while
getHeaders() returns null when res is absent, creating an inconsistent contract;
change the constructor assignment to this.headers = res ? res.headers : null so
this.headers and getHeaders() both return null when res is missing (refer to the
this.headers initialization and the getHeaders() method to locate the code).
---
Outside diff comments:
In `@packages/bruno-js/src/bruno-request.js`:
- Line 21: The constructor currently does this.headers = req.headers which
creates a stale reference when setHeaders(headers) reassigns this.req.headers;
fix by making the public shorthand always reflect the current request headers —
either convert headers into a getter that returns this.req.headers (so
headerList and external reads always see the live object) or ensure
setHeaders(headers) also updates this.headers to point at the new object; apply
the same fix/consistency to the other places noted (e.g., the code around
setHeader/deleteHeader and the block at lines ~131-133) so no API surface can
drift from this.req.headers.
- Around line 101-120: Update getAuthMode() to perform case-insensitive header
checks for Authorization and X-WSSE like hasJSONContentType() does: when
checking for bearer/basic auth and WSSE, also consult headers['authorization']
and headers['x-wsse'] fallbacks (in addition to headers['Authorization'] and
headers['X-WSSE']) so startsWith('Bearer')/startsWith('Basic')/presence checks
work regardless of header casing; modify the branches in getAuthMode()
accordingly (preserving existing checks on this.req.oauth2, oauth1config,
auth.username, awsv4, digestConfig) so behavior is identical but tolerant to
header case variations.
🪄 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: 13386519-96d1-4ba4-b4d1-55e2e4cdca55
📒 Files selected for processing (3)
packages/bruno-js/src/bruno-request.jspackages/bruno-js/src/bruno-response.jspackages/bruno-js/tests/header-list.spec.js
✅ Files skipped from review due to trivial changes (1)
- packages/bruno-js/tests/header-list.spec.js
…est and BrunoResponse - Implemented HeaderList to provide a dynamic API for managing request headers, allowing real-time reflection of changes. - Updated BrunoRequest and BrunoResponse to utilize HeaderList for header access, enhancing consistency and usability. - Added a headers proxy to maintain backward compatibility with existing header access patterns. - Introduced tests for HeaderList to ensure functionality and reliability across various header operations.
…aw headers - Modified createHeadersProxy to allow passing a function that retrieves raw headers, enhancing flexibility in header management. - Updated HeaderList to utilize the new getter function, ensuring consistent behavior when headers are modified. - Added a test to verify that bracket access reflects changes made via BrunoRequest.setHeaders.
…der management - Updated createHeadersProxy to clarify precedence of PropertyList methods over header names in bracket access. - Expanded syncWriteMethods in bruno-request shim to include additional methods for better header manipulation. - Implemented a custom remove method in property-list-bridge to handle function predicates in-VM, improving the native bridge's functionality.
- Renamed `req.headers` to `req.headerList` for improved clarity and consistency in header operations. - Enhanced `HeaderList` to support both dynamic and static modes for header management. - Updated shims for `req` and `res` to reflect the new header access patterns. - Modified tests to validate the new header access methods and ensure backward compatibility with raw headers.
…noResponse - Added comprehensive translations for `req.headerList` and `res.headerList` methods to their respective Postman equivalents, improving consistency in header management. - Updated tests to validate the new translation methods, ensuring accurate conversion between Bruno and Postman header operations. - Enhanced existing tests to cover additional header manipulation scenarios, reinforcing the reliability of the header management system.
…unoResponse - Replaced lazy initialization of `headerList` with direct instantiation in both classes for improved performance and clarity. - Removed redundant getter methods for `headerList`, simplifying the API. - Updated tests to reflect changes in headerList instantiation and ensure proper functionality.
41bf434 to
b74f8c1
Compare
- Introduced multiple test files for `req.headerList` and `res.headerList` methods, covering various operations such as add, remove, clear, populate, and search methods. - Implemented tests for both dynamic and read-only scenarios, ensuring robust validation of header management functionalities. - Enhanced existing headerList methods with detailed assertions to improve reliability and maintainability of the header management system.
…req and res - Added a comprehensive list of methods for `req.headerList` and `res.headerList` to enhance autocomplete functionality. - Included various operations such as get, add, remove, and manipulation methods to improve developer experience and usability.
- Added functionality to track disabled headers in `req.headerList` and `res.headerList`, allowing for better management of header states. - Updated the `prepareRequest` and `prepareGrpcRequest` functions to include a `disabledHeaders` property. - Enhanced the `HeaderList` class to handle disabled headers, including methods to filter, count, and retrieve them. - Introduced tests to validate the behavior of disabled headers, ensuring they are correctly included in the header list while being excluded from raw headers.
…ed toObject method - Implemented case-insensitive key lookups for methods such as get, one, has, and indexOf in HeaderList. - Updated toObject method to support options for excluding disabled headers, handling duplicate keys, and skipping headers with falsy keys. - Modified toString method to return headers in HTTP wire format, improving consistency with standard practices. - Added comprehensive tests to validate new functionalities, ensuring robust header management and accurate behavior for both enabled and disabled headers.
- Enhanced iteration methods (each, filter, find, map, reduce) in HeaderList to accept an optional context parameter, allowing for better control over the `this` binding in callback functions. - Updated the remove method to support context binding for function predicates. - Added comprehensive tests to validate the new context binding functionality across various iteration methods, ensuring robust header management.
…ect support - Added support for accepting an object with a key property in the `has` method, improving header existence checks. - Updated `add` and `populate` methods to accept "Key: Value" strings and multi-line header strings, enhancing flexibility in header management. - Modified `toString` method to ensure a trailing newline in the output, aligning with HTTP wire format standards. - Introduced comprehensive tests to validate new functionalities, ensuring robust header management and accurate behavior for various input types.
… context binding - Updated `mergeHeaders` function to preserve disabled headers from the request item, improving header state management. - Modified `addBrunoRequestShimToContext` and `addBrunoResponseShimToContext` to wrap eval code in blocks, preventing redeclaration conflicts. - Enhanced iteration methods in `property-list-bridge` to support context binding, allowing for better control over `this` in callbacks. - Added comprehensive tests for `req.headerList` and `res.headerList` to validate new functionalities and ensure robust header management.
…t items - Enhanced the `mergeHeaders` function to retain disabled headers from the last entry in the request tree path, ensuring better management of header states. - Updated the logic to include disabled headers while merging, improving the overall functionality of header management.
…ders - Refactored the `mergeHeaders` function to utilize a separate array for disabled headers, ensuring they are preserved during the merging process. - Simplified the logic for merging headers by directly combining enabled and disabled headers into the request object, enhancing clarity and maintainability.
- Changed the implementation of disabled headers from an array to a Map for better performance and consistency. - Updated the logic in the `mergeHeaders` function to ensure disabled headers are correctly merged into the request object. - Enhanced tests to validate the handling of disabled headers, including new scenarios for folder-level and request-level overrides.
…disabled headers - Updated the `mergeHeaders` function to accept an options parameter, allowing for the inclusion of disabled headers in the merged result. - Modified the logic to handle disabled headers more effectively, ensuring they can be returned based on the provided options. - Adjusted calls to `mergeHeaders` in various modules to utilize the new functionality, improving header management consistency across the application.
- Eliminated the handling of disabledHeaders in the prepareGrpcRequest function to streamline header management. - Updated the headers processing logic to focus solely on enabled headers, enhancing clarity and reducing complexity.
- Introduced new tests to translate methods from req.headerList and res.headerList to their corresponding pm.request.headers and pm.response.headers methods. - Added translations for methods: one, find, toObject, and upsert, enhancing the functionality of the header management system.
- Enhanced documentation for `prepend`, `append`, `insert`, and `insertAfter` methods to clarify that they are aliases for `add()` and include a note on the lack of support for ordering and duplicates. - Updated method comments to reflect the internal handling of headers as a plain object, ensuring better understanding of header management behavior.
- Eliminated redundant initialization of headerList in the BrunoRequest constructor, ensuring cleaner code and preventing potential issues with header management. - This change simplifies the constructor logic while maintaining the intended functionality of the headerList.
…ation - Removed the unimplemented methods `prepend`, `append`, `insert`, and `insertAfter` from the headerList, ensuring clarity in the API. - Updated documentation to reflect that these methods are not implemented and provide guidance to use `add()` or `upsert()` instead. - Adjusted tests to verify that calls to these methods throw appropriate not-implemented errors, enhancing the robustness of header management.
- Eliminated the call to `req.headerList.append()` in the pre-request script, streamlining the header management process. - This change aligns with the recent refactor to remove unimplemented methods, ensuring clarity and consistency in the API usage.
- Changed error messages in tests for `append`, `prepend`, `insert`, and `insertAfter` methods to indicate they are "not yet implemented" instead of "not implemented". - This update improves clarity in the test outputs, aligning with the current state of the headerList API.
…tests - Eliminated the unimplemented methods `prepend`, `append`, `insert`, and `insertAfter` from the HeaderList class and corresponding tests, clarifying the API usage. - Updated the documentation to guide users towards using `add()` or `upsert()` instead. - Adjusted tests to remove references to these methods, ensuring they accurately reflect the current state of the headerList API.
- Modified the HeaderList class to accept the raw request and response objects directly, simplifying the initialization process. - Updated the BrunoRequest and BrunoResponse classes to reflect this change, ensuring consistent handling of headers. - Enhanced internal methods to utilize the new structure, improving clarity and maintainability of the header management system.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/bruno-js/src/header-list.js (1)
98-107: 💤 Low valueConsider documenting the ordering rationale.
The dataSource places disabled headers before enabled ones (
[...disabled, ...enabled]). Combined withfindLast()inget()/one(), this correctly prioritizes enabled headers over disabled ones with the same key. The intent is clear but a brief inline comment would help future maintainers understand this deliberate ordering.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-js/src/header-list.js` around lines 98 - 107, Add a brief inline comment in the dataSource function explaining why disabled headers are placed before enabled ones (returning [...disabled, ...enabled]) so that combined with findLast() used in get()/one(), enabled headers override disabled ones for the same key; reference the dataSource function and the get()/one() usages of findLast() to make the intentional ordering explicit for future maintainers.tests/scripting/req-api/headerList/headerList.spec.ts (1)
5-25: ⚡ Quick winWrap each step in
test.stepper project test guidelines.Neither test uses
test.step, which means the Playwright HTML report shows a flat list of assertions rather than labelled phases. Given the clear sequential flow, this is a quick win.♻️ Proposed refactor
test('all req.headerList tests pass in developer mode', async ({ pageWithUserData: page }) => { - await setSandboxMode(page, 'bruno-testbench', 'developer'); - await selectEnvironment(page, 'Prod'); - await runFolder(page, 'bruno-testbench', ['scripting', 'api', 'req', 'headerList']); - await validateRunnerResults(page, { - totalRequests: 13, - passed: 13, - failed: 0 - }); + await test.step('set sandbox to developer mode', () => + setSandboxMode(page, 'bruno-testbench', 'developer')); + await test.step('select Prod environment', () => + selectEnvironment(page, 'Prod')); + await test.step('run headerList folder', () => + runFolder(page, 'bruno-testbench', ['scripting', 'api', 'req', 'headerList'])); + await test.step('validate runner results', () => + validateRunnerResults(page, { totalRequests: 13, passed: 13, failed: 0 })); }); test('all req.headerList tests pass in safe mode', async ({ pageWithUserData: page }) => { - await setSandboxMode(page, 'bruno-testbench', 'safe'); - await selectEnvironment(page, 'Prod'); - await runFolder(page, 'bruno-testbench', ['scripting', 'api', 'req', 'headerList']); - await validateRunnerResults(page, { - totalRequests: 13, - passed: 13, - failed: 0 - }); + await test.step('set sandbox to safe mode', () => + setSandboxMode(page, 'bruno-testbench', 'safe')); + await test.step('select Prod environment', () => + selectEnvironment(page, 'Prod')); + await test.step('run headerList folder', () => + runFolder(page, 'bruno-testbench', ['scripting', 'api', 'req', 'headerList'])); + await test.step('validate runner results', () => + validateRunnerResults(page, { totalRequests: 13, passed: 13, failed: 0 })); });As per coding guidelines: "Promote the use of
test.stepas much as possible so the generated reports are easier to read."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/scripting/req-api/headerList/headerList.spec.ts` around lines 5 - 25, The tests "all req.headerList tests pass in developer mode" and "all req.headerList tests pass in safe mode" should wrap each logical operation in a test.step to improve reporting: replace the direct awaits to setSandboxMode, selectEnvironment, runFolder, and validateRunnerResults with individual test.step blocks (use the same descriptive labels) inside each test function so steps like setSandboxMode(page, 'bruno-testbench', 'developer'|'safe'), selectEnvironment(page, 'Prod'), runFolder(page, ['scripting','api','req','headerList']), and validateRunnerResults(page, {...}) are executed inside test.step callbacks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/bruno-js/tests/header-list.spec.js`:
- Around line 672-684: Update the upsert() implementation to track removed
headers the same way remove() does: when you detect an existing header with
different casing (the local variable existingKey in upsert()), call the private
helper `#deleteHeader`(existingKey) instead of directly deleting
headers[existingKey] so the original casing is recorded in
rawReq.__headersToDelete; keep the existing `#deleteHeaderCI`() logic unchanged.
Then update the tests: after calling list.remove('content-type') add an
assertion that rawReq.__headersToDelete contains 'Content-Type', and after
calling list.upsert({ key: 'content-type', value: 'text/plain' }) add an
assertion that rawReq.__headersToDelete contains 'Content-Type' to verify
case-insensitive tracking.
In
`@packages/bruno-tests/collection/scripting/api/req/headerList/disabled-headers.bru`:
- Around line 46-50: The test "req.headerList.count() includes disabled headers"
is recomputing the count from req.headerList.all() instead of calling
req.headerList.count(), which hides regressions in the bridge; update the
assertion to call req.headerList.count() and assert it equals 5 (e.g., const
count = req.headerList.count(); expect(count).to.equal(5)), leaving the rest of
the test and the brunoHeaders filtering unchanged so the test still documents
which headers are expected.
---
Nitpick comments:
In `@packages/bruno-js/src/header-list.js`:
- Around line 98-107: Add a brief inline comment in the dataSource function
explaining why disabled headers are placed before enabled ones (returning
[...disabled, ...enabled]) so that combined with findLast() used in get()/one(),
enabled headers override disabled ones for the same key; reference the
dataSource function and the get()/one() usages of findLast() to make the
intentional ordering explicit for future maintainers.
In `@tests/scripting/req-api/headerList/headerList.spec.ts`:
- Around line 5-25: The tests "all req.headerList tests pass in developer mode"
and "all req.headerList tests pass in safe mode" should wrap each logical
operation in a test.step to improve reporting: replace the direct awaits to
setSandboxMode, selectEnvironment, runFolder, and validateRunnerResults with
individual test.step blocks (use the same descriptive labels) inside each test
function so steps like setSandboxMode(page, 'bruno-testbench',
'developer'|'safe'), selectEnvironment(page, 'Prod'), runFolder(page,
['scripting','api','req','headerList']), and validateRunnerResults(page, {...})
are executed inside test.step callbacks.
🪄 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: 58fa761d-387f-4081-9379-6de91ade736a
📒 Files selected for processing (45)
packages/bruno-app/src/utils/codemirror/autocomplete.jspackages/bruno-app/src/utils/collections/index.jspackages/bruno-cli/src/runner/prepare-request.jspackages/bruno-cli/src/utils/collection.jspackages/bruno-converters/src/utils/bruno-to-postman-translator.jspackages/bruno-converters/src/utils/postman-to-bruno-translator.jspackages/bruno-converters/tests/bruno/bruno-to-postman-translations/request.test.jspackages/bruno-converters/tests/bruno/bruno-to-postman-translations/response.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/legacy-tests-syntax.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/request.test.jspackages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.jspackages/bruno-electron/src/ipc/network/prepare-request.jspackages/bruno-electron/src/utils/collection.jspackages/bruno-js/src/bruno-request.jspackages/bruno-js/src/bruno-response.jspackages/bruno-js/src/header-list.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-request.jspackages/bruno-js/src/sandbox/quickjs/shims/bruno-response.jspackages/bruno-js/src/sandbox/quickjs/utils/property-list-bridge.jspackages/bruno-js/tests/header-list.spec.jspackages/bruno-tests/collection/scripting/api/req/headerList/add.brupackages/bruno-tests/collection/scripting/api/req/headerList/assimilate.brupackages/bruno-tests/collection/scripting/api/req/headerList/case-insensitive-write.brupackages/bruno-tests/collection/scripting/api/req/headerList/case-insensitive.brupackages/bruno-tests/collection/scripting/api/req/headerList/clear.brupackages/bruno-tests/collection/scripting/api/req/headerList/context-binding.brupackages/bruno-tests/collection/scripting/api/req/headerList/disabled-headers.brupackages/bruno-tests/collection/scripting/api/req/headerList/folder.brupackages/bruno-tests/collection/scripting/api/req/headerList/iteration-methods.brupackages/bruno-tests/collection/scripting/api/req/headerList/populate.brupackages/bruno-tests/collection/scripting/api/req/headerList/read-methods.brupackages/bruno-tests/collection/scripting/api/req/headerList/remove.brupackages/bruno-tests/collection/scripting/api/req/headerList/search-methods.brupackages/bruno-tests/collection/scripting/api/req/headerList/transform-methods.brupackages/bruno-tests/collection/scripting/api/res/headerList/case-insensitive.brupackages/bruno-tests/collection/scripting/api/res/headerList/iteration-methods.brupackages/bruno-tests/collection/scripting/api/res/headerList/read-methods.brupackages/bruno-tests/collection/scripting/api/res/headerList/search-methods.brupackages/bruno-tests/collection/scripting/api/res/headerList/transform-methods.brutests/scripting/req-api/headerList/headerList.spec.tstests/scripting/req-api/headerList/init-user-data/collection-security.jsontests/scripting/req-api/headerList/init-user-data/preferences.jsontests/scripting/res-api/headerList/headerList.spec.tstests/scripting/res-api/headerList/init-user-data/collection-security.jsontests/scripting/res-api/headerList/init-user-data/preferences.json
✅ Files skipped from review due to trivial changes (20)
- tests/scripting/res-api/headerList/init-user-data/collection-security.json
- tests/scripting/req-api/headerList/init-user-data/preferences.json
- packages/bruno-tests/collection/scripting/api/req/headerList/add.bru
- tests/scripting/req-api/headerList/init-user-data/collection-security.json
- packages/bruno-tests/collection/scripting/api/req/headerList/folder.bru
- packages/bruno-tests/collection/scripting/api/res/headerList/iteration-methods.bru
- packages/bruno-tests/collection/scripting/api/req/headerList/populate.bru
- packages/bruno-tests/collection/scripting/api/res/headerList/read-methods.bru
- packages/bruno-tests/collection/scripting/api/req/headerList/context-binding.bru
- packages/bruno-tests/collection/scripting/api/req/headerList/search-methods.bru
- packages/bruno-tests/collection/scripting/api/req/headerList/remove.bru
- tests/scripting/res-api/headerList/init-user-data/preferences.json
- packages/bruno-tests/collection/scripting/api/res/headerList/search-methods.bru
- packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/legacy-tests-syntax.test.js
- packages/bruno-tests/collection/scripting/api/req/headerList/iteration-methods.bru
- tests/scripting/res-api/headerList/headerList.spec.ts
- packages/bruno-tests/collection/scripting/api/req/headerList/assimilate.bru
- packages/bruno-tests/collection/scripting/api/req/headerList/read-methods.bru
- packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/request.test.js
- packages/bruno-converters/src/utils/postman-to-bruno-translator.js
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/bruno-converters/tests/postman/postman-translations/transpiler-tests/response.test.js
- packages/bruno-converters/tests/bruno/bruno-to-postman-translations/response.test.js
- packages/bruno-converters/src/utils/bruno-to-postman-translator.js
- packages/bruno-js/src/bruno-request.js
- packages/bruno-converters/tests/bruno/bruno-to-postman-translations/request.test.js
- Updated HeaderList to track removed headers for axios interceptor, improving header casing handling. - Added new syncWriteMethods to the BrunoResponse shim for better integration. - Enhanced tests to verify the correct tracking of deleted headers and updated expectations for header management functionality.
- Removed unused 'idx' translations from both bruno-to-postman and postman-to-bruno translators to streamline header management. - Enhanced the HeaderList class to skip existing keys when populating headers, ensuring that current values are preserved. - Updated tests to reflect the new behavior of the populate method, verifying that existing headers are not overwritten and adjusting expectations accordingly.
- Modified the req.headerList.populate method to add new headers while preserving existing ones, ensuring that current values are not overwritten. - Updated the associated test to reflect this new behavior, verifying that existing headers remain intact and new headers are correctly added.
- Renamed `each` method to `forEach` in HeaderList for consistency with standard JavaScript array methods. - Updated header management methods: replaced `add` with `append`, `upsert` with `set`, and `remove` with `delete` to better reflect their functionality. - Enhanced translations in bruno-to-postman and postman-to-bruno converters to align with the new method names. - Adjusted tests to verify the new method names and ensure correct header management behavior.
- Removed the `entries`, `keys`, and `values` methods from the HeaderList class to streamline the API and eliminate unused functionality. - Updated the `bruno-request` and `bruno-response` shims to reflect the removal of these methods, ensuring consistency in header management. - Adjusted tests to remove references to the deleted methods, maintaining alignment with the current state of the headerList API.
- Updated the HeaderList class to remove headers from the __headersToDelete array when they are re-added, preventing incorrect header deletion behavior. - Added tests to verify that re-added headers do not remain in __headersToDelete and that their values are correctly set in the raw request headers.
…7673) * feat: introduce HeaderList for dynamic header management in BrunoRequest and BrunoResponse - Implemented HeaderList to provide a dynamic API for managing request headers, allowing real-time reflection of changes. - Updated BrunoRequest and BrunoResponse to utilize HeaderList for header access, enhancing consistency and usability. - Added a headers proxy to maintain backward compatibility with existing header access patterns. - Introduced tests for HeaderList to ensure functionality and reliability across various header operations. * refactor: update createHeadersProxy to accept a getter function for raw headers - Modified createHeadersProxy to allow passing a function that retrieves raw headers, enhancing flexibility in header management. - Updated HeaderList to utilize the new getter function, ensuring consistent behavior when headers are modified. - Added a test to verify that bracket access reflects changes made via BrunoRequest.setHeaders. * refactor: enhance headers proxy and syncWriteMethods for improved header management - Updated createHeadersProxy to clarify precedence of PropertyList methods over header names in bracket access. - Expanded syncWriteMethods in bruno-request shim to include additional methods for better header manipulation. - Implemented a custom remove method in property-list-bridge to handle function predicates in-VM, improving the native bridge's functionality. * refactor: update header management in BrunoRequest and BrunoResponse - Renamed `req.headers` to `req.headerList` for improved clarity and consistency in header operations. - Enhanced `HeaderList` to support both dynamic and static modes for header management. - Updated shims for `req` and `res` to reflect the new header access patterns. - Modified tests to validate the new header access methods and ensure backward compatibility with raw headers. * refactor: enhance header translation methods for BrunoRequest and BrunoResponse - Added comprehensive translations for `req.headerList` and `res.headerList` methods to their respective Postman equivalents, improving consistency in header management. - Updated tests to validate the new translation methods, ensuring accurate conversion between Bruno and Postman header operations. - Enhanced existing tests to cover additional header manipulation scenarios, reinforcing the reliability of the header management system. * refactor: streamline headerList implementation in BrunoRequest and BrunoResponse - Replaced lazy initialization of `headerList` with direct instantiation in both classes for improved performance and clarity. - Removed redundant getter methods for `headerList`, simplifying the API. - Updated tests to reflect changes in headerList instantiation and ensure proper functionality. * refactor: remove header proxy * feat: add comprehensive headerList tests for request and response - Introduced multiple test files for `req.headerList` and `res.headerList` methods, covering various operations such as add, remove, clear, populate, and search methods. - Implemented tests for both dynamic and read-only scenarios, ensuring robust validation of header management functionalities. - Enhanced existing headerList methods with detailed assertions to improve reliability and maintainability of the header management system. * feat: expand STATIC_API_HINTS with additional headerList methods for req and res - Added a comprehensive list of methods for `req.headerList` and `res.headerList` to enhance autocomplete functionality. - Included various operations such as get, add, remove, and manipulation methods to improve developer experience and usability. * feat: implement support for disabled headers in headerList - Added functionality to track disabled headers in `req.headerList` and `res.headerList`, allowing for better management of header states. - Updated the `prepareRequest` and `prepareGrpcRequest` functions to include a `disabledHeaders` property. - Enhanced the `HeaderList` class to handle disabled headers, including methods to filter, count, and retrieve them. - Introduced tests to validate the behavior of disabled headers, ensuring they are correctly included in the header list while being excluded from raw headers. * feat: enhance HeaderList with case-insensitive key lookups and improved toObject method - Implemented case-insensitive key lookups for methods such as get, one, has, and indexOf in HeaderList. - Updated toObject method to support options for excluding disabled headers, handling duplicate keys, and skipping headers with falsy keys. - Modified toString method to return headers in HTTP wire format, improving consistency with standard practices. - Added comprehensive tests to validate new functionalities, ensuring robust header management and accurate behavior for both enabled and disabled headers. * feat: add context binding to iteration methods in HeaderList - Enhanced iteration methods (each, filter, find, map, reduce) in HeaderList to accept an optional context parameter, allowing for better control over the `this` binding in callback functions. - Updated the remove method to support context binding for function predicates. - Added comprehensive tests to validate the new context binding functionality across various iteration methods, ensuring robust header management. * feat: enhance HeaderList with new methods for string handling and object support - Added support for accepting an object with a key property in the `has` method, improving header existence checks. - Updated `add` and `populate` methods to accept "Key: Value" strings and multi-line header strings, enhancing flexibility in header management. - Modified `toString` method to ensure a trailing newline in the output, aligning with HTTP wire format standards. - Introduced comprehensive tests to validate new functionalities, ensuring robust header management and accurate behavior for various input types. * feat: enhance header management with support for disabled headers and context binding - Updated `mergeHeaders` function to preserve disabled headers from the request item, improving header state management. - Modified `addBrunoRequestShimToContext` and `addBrunoResponseShimToContext` to wrap eval code in blocks, preventing redeclaration conflicts. - Enhanced iteration methods in `property-list-bridge` to support context binding, allowing for better control over `this` in callbacks. - Added comprehensive tests for `req.headerList` and `res.headerList` to validate new functionalities and ensure robust header management. * feat: improve header merging to preserve disabled headers from request items - Enhanced the `mergeHeaders` function to retain disabled headers from the last entry in the request tree path, ensuring better management of header states. - Updated the logic to include disabled headers while merging, improving the overall functionality of header management. * feat: update header merging logic to consistently handle disabled headers - Refactored the `mergeHeaders` function to utilize a separate array for disabled headers, ensuring they are preserved during the merging process. - Simplified the logic for merging headers by directly combining enabled and disabled headers into the request object, enhancing clarity and maintainability. * refactor: update disabled headers handling in mergeHeaders function - Changed the implementation of disabled headers from an array to a Map for better performance and consistency. - Updated the logic in the `mergeHeaders` function to ensure disabled headers are correctly merged into the request object. - Enhanced tests to validate the handling of disabled headers, including new scenarios for folder-level and request-level overrides. * feat: enhance mergeHeaders function to support optional inclusion of disabled headers - Updated the `mergeHeaders` function to accept an options parameter, allowing for the inclusion of disabled headers in the merged result. - Modified the logic to handle disabled headers more effectively, ensuring they can be returned based on the provided options. - Adjusted calls to `mergeHeaders` in various modules to utilize the new functionality, improving header management consistency across the application. * refactor: remove disabledHeaders from prepareGrpcRequest function - Eliminated the handling of disabledHeaders in the prepareGrpcRequest function to streamline header management. - Updated the headers processing logic to focus solely on enabled headers, enhancing clarity and reducing complexity. * feat: add translations for req.headerList and res.headerList methods - Introduced new tests to translate methods from req.headerList and res.headerList to their corresponding pm.request.headers and pm.response.headers methods. - Added translations for methods: one, find, toObject, and upsert, enhancing the functionality of the header management system. * docs: update HeaderList method aliases and add clarification notes - Enhanced documentation for `prepend`, `append`, `insert`, and `insertAfter` methods to clarify that they are aliases for `add()` and include a note on the lack of support for ordering and duplicates. - Updated method comments to reflect the internal handling of headers as a plain object, ensuring better understanding of header management behavior. * fix: remove duplicate headerList initialization in BrunoRequest class - Eliminated redundant initialization of headerList in the BrunoRequest constructor, ensuring cleaner code and preventing potential issues with header management. - This change simplifies the constructor logic while maintaining the intended functionality of the headerList. * refactor: remove unimplemented headerList methods and update documentation - Removed the unimplemented methods `prepend`, `append`, `insert`, and `insertAfter` from the headerList, ensuring clarity in the API. - Updated documentation to reflect that these methods are not implemented and provide guidance to use `add()` or `upsert()` instead. - Adjusted tests to verify that calls to these methods throw appropriate not-implemented errors, enhancing the robustness of header management. * refactor: remove unused headerList append method from pre-request script - Eliminated the call to `req.headerList.append()` in the pre-request script, streamlining the header management process. - This change aligns with the recent refactor to remove unimplemented methods, ensuring clarity and consistency in the API usage. * test: update error messages for unimplemented headerList methods - Changed error messages in tests for `append`, `prepend`, `insert`, and `insertAfter` methods to indicate they are "not yet implemented" instead of "not implemented". - This update improves clarity in the test outputs, aligning with the current state of the headerList API. * refactor: remove unimplemented headerList methods and update related tests - Eliminated the unimplemented methods `prepend`, `append`, `insert`, and `insertAfter` from the HeaderList class and corresponding tests, clarifying the API usage. - Updated the documentation to guide users towards using `add()` or `upsert()` instead. - Adjusted tests to remove references to these methods, ensuring they accurately reflect the current state of the headerList API. * refactor: update HeaderList to accept raw request and response objects - Modified the HeaderList class to accept the raw request and response objects directly, simplifying the initialization process. - Updated the BrunoRequest and BrunoResponse classes to reflect this change, ensuring consistent handling of headers. - Enhanced internal methods to utilize the new structure, improving clarity and maintainability of the header management system. * refactor: enhance HeaderList header management and update tests - Updated HeaderList to track removed headers for axios interceptor, improving header casing handling. - Added new syncWriteMethods to the BrunoResponse shim for better integration. - Enhanced tests to verify the correct tracking of deleted headers and updated expectations for header management functionality. * refactor: update header translations and improve HeaderList methods - Removed unused 'idx' translations from both bruno-to-postman and postman-to-bruno translators to streamline header management. - Enhanced the HeaderList class to skip existing keys when populating headers, ensuring that current values are preserved. - Updated tests to reflect the new behavior of the populate method, verifying that existing headers are not overwritten and adjusting expectations accordingly. * refactor: update headerList.populate behavior and adjust tests - Modified the req.headerList.populate method to add new headers while preserving existing ones, ensuring that current values are not overwritten. - Updated the associated test to reflect this new behavior, verifying that existing headers remain intact and new headers are correctly added. * refactor: update HeaderList methods and translations for consistency - Renamed `each` method to `forEach` in HeaderList for consistency with standard JavaScript array methods. - Updated header management methods: replaced `add` with `append`, `upsert` with `set`, and `remove` with `delete` to better reflect their functionality. - Enhanced translations in bruno-to-postman and postman-to-bruno converters to align with the new method names. - Adjusted tests to verify the new method names and ensure correct header management behavior. * refactor: remove unused headerList methods and update related shims - Removed the `entries`, `keys`, and `values` methods from the HeaderList class to streamline the API and eliminate unused functionality. - Updated the `bruno-request` and `bruno-response` shims to reflect the removal of these methods, ensuring consistency in header management. - Adjusted tests to remove references to the deleted methods, maintaining alignment with the current state of the headerList API. * fix: ensure re-added headers are removed from __headersToDelete - Updated the HeaderList class to remove headers from the __headersToDelete array when they are re-added, preventing incorrect header deletion behavior. - Added tests to verify that re-added headers do not remain in __headersToDelete and that their values are correctly set in the raw request headers.
Jira
Summary
Adds a
headerListproperty to bothreqandresin scripts, exposing a structured PropertyList API for header management. Method names are aligned with the MDN Web API Headers interface. The existingreq.headersandres.headersraw objects remain untouched for full backward compatibility.New API
req.headerList— writableHeaderList(extendsPropertyList, dynamic mode):res.headerList— read-onlyHeaderList(static mode, write methods throw):Key design decisions
req.headerList/res.headerListis distinct fromreq.headers/res.headers— no Proxy layer, no risk of breaking existing scriptsappend,set,delete,forEach(matching MDN Headers)req.headerListsurfaces disabled headers with{ disabled: true }— users can query/filter themreq.headerListreads from the livereq.headersobject on every access, so mutations viareq.setHeader()are always reflectedappendvs MDN'sHeaders.append()MDN's
append()creates duplicate headers with the same key. Bruno does not support multiple headers with the same name, soappend()delegates toset()— it overwrites any existing header with the same key.populateandrepopulatepopulate(items)— Adds headers from the array/string, but skips any key that already exists (case-insensitive). Postman'spopulateadds duplicate keys because Postman supports multiple headers with the same name. Bruno does not, so we skip existing keys to preserve the current value.repopulate(items)— Clears all existing headers first, then adds the new items. Matches Postman'srepopulatebehavior.Complete API Reference
All key lookups are case-insensitive per the HTTP spec.
req.headerList— Request Headers (read-write)Read Methods
get(name)string | undefinedone(name)object | undefined{ key, value }for the matching keyall()object[]{ key, value, disabled? }count()numberSearch Methods
has(name)booleantrueif a header with that key existshas(name, value)booleantrueif key exists and value matches exactlyhas(object)booleantrueif a header withobject.keyexistsfind(fn, context?)object | undefinedfilter(fn, context?)object[]indexOf(item)number{ key, value }object;-1if not foundIteration Methods
forEach(fn, context?)voidfn(header, index)for every headermap(fn, context?)any[]reduce(fn, initial?, context?)anyTransform Methods
toObject(excludeDisabled?, caseSensitive?, multiValue?, sanitizeKeys?)object{ key: value }maptoString()stringKey: Value\n...(skips disabled headers)toJSON()object[]all()— suitable forJSON.stringify()Write Methods
append(headerObj | name, value?)void{ key, value },"Key: Value"string, or(name, value)two-arg form. Delegates toset()(overwrites existing).set(headerObj | name, value?)boolean | nulltrueif new,falseif updated,nullif input was nil.delete(predicate, context?)void{ key }object, or predicate functionclear()voidpopulate(items | string)voidrepopulate(items | string)voidassimilate(source, prune?)voidpruneis true, removes headers not present in sourceres.headerList— Response Headers (read-only)All write methods (
append,set,delete,clear,populate,repopulate,assimilate) throw a"HeaderList is read-only"error when called on response headers.Read Methods
get(name)string | undefinedone(name)object | undefined{ key, value }for the matching keyall()object[]{ key, value }count()numberSearch Methods
has(name)booleantrueif a header with that key existshas(name, value)booleantrueif key exists and value matches exactlyhas(object)booleantrueif a header withobject.keyexistsfind(fn, context?)object | undefinedfilter(fn, context?)object[]indexOf(item)number{ key, value }object;-1if not foundIteration Methods
forEach(fn, context?)voidfn(header, index)for every headermap(fn, context?)any[]reduce(fn, initial?, context?)anyTransform Methods
toObject(excludeDisabled?, caseSensitive?, multiValue?, sanitizeKeys?)object{ key: value }maptoString()stringKey: Value\n...toJSON()object[]all()— suitable forJSON.stringify()Contribution Checklist: