Skip to content

Conversation

@danielkitchener
Copy link

@danielkitchener danielkitchener commented Jan 23, 2026

Description

Fixes #6916 by parsing the Content-Type value to extract the media-type component and use that for determining whether or not to form-urlencode parameters.

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. (in the original issue)
  • 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.

Publishing to New Package Managers

Please see here for more information.

Note:
I wasn't quite sure how to answer the first question in the Contribution Checklist (whether I used AI "significantly"). I answered "no", but I'm unsure what the threshold for "significantly" is.

In full disclosure, while I authored most of this change myself, I used Windsurf/Cascade editor for the following:

  • During debugging, I used it to help me identify the part of the code where the request parameter encoding was occurring.
  • When writing the tests, I used it to help get the tests working, as it was much quicker for me to ask it what the selectors for specific fields would be, rather than dig through the codebase myself
  • I asked it to double-check my work several times to ensure that I hadn't made any silly mistakes.

In my opinion, this isn't "significant" use, as it's using an AI-enhanced editor as a tool rather than a vibe-coding style code generator, but I want to be as transparent as possible due to lack of a definition of what "significant" entails in this case. I'm willing to update my answer to "yes" if my use does meet that threshold.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed form-encoded request handling to correctly process Content-Type headers that include additional parameters (e.g., charset specifications), ensuring requests are properly formatted regardless of header formatting.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

This PR fixes a bug where Content-Type headers containing additional parameters (charset, boundary) were causing incorrect form-encoded POST body formatting. A media type parsing improvement enables proper detection of form-encoded and multipart requests regardless of header parameters, with comprehensive test coverage added for various scenarios.

Changes

Cohort / File(s) Summary
Content-Type Header Parsing Fix
packages/bruno-electron/src/ipc/network/index.js
Extracts base media type from Content-Type header before parameter parsing. Replaces direct string matching of full header value with mediaType variable comparison, allowing correct handling of headers like application/x-www-form-urlencoded; charset=utf-8
Form URL Encoding Test Coverage
tests/request/encoding/form-url-encoding.spec.ts
Adds three Playwright integration tests verifying form-urlencoded behavior: (1) without explicit Content-Type, (2) with charset parameter, (3) with multiple parameters (charset + boundary). Each test validates correct payload encoding in POST requests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

size/M

Suggested reviewers

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

Poem

📝 Headers with charset, oh what a plight,
Form bodies mangled, not encoded right,
Parse the media type, strip parameters free,
Now POST requests work as they ought to be! ✨

🚥 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 and concisely describes the main fix: parsing Content-Type headers to handle charset and boundary parameters.
Linked Issues check ✅ Passed The PR directly addresses issue #6916 by refactoring Content-Type parsing to extract the media-type component before parameters, enabling correct form-urlencoding regardless of charset/boundary parameters.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing Content-Type parsing: the network IPC handler refactor and three comprehensive test cases validating the fix against the reported scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-electron/src/ipc/network/index.js (1)

517-531: Normalize mediaType to handle case-insensitive header values.
HTTP media types are case-insensitive; a mixed-case value would skip the encoding branch. Consider lowercasing when extracting.

💡 Suggested adjustment
-    if (contentTypeHeader && request.headers[contentTypeHeader]) {
-      mediaType = request.headers[contentTypeHeader].split(';')[0].trim();
-    }
+    if (contentTypeHeader && request.headers[contentTypeHeader]) {
+      mediaType = request.headers[contentTypeHeader].split(';')[0].trim().toLowerCase();
+    }
🧹 Nitpick comments (1)
tests/request/encoding/form-url-encoding.spec.ts (1)

16-186: Factor repeated UI steps into helpers/locators for maintainability.
The three tests repeat method selection, body-mode selection, and send/wait steps. Extracting small helpers makes updates safer if selectors change.

♻️ Example helper extraction
 test.describe('Form URL Encoding with Content-Type Parameters', () => {
+  const selectPostMethod = async (page) => {
+    await page.locator('.method-selector').click();
+    await page.locator('.dropdown-item').filter({ hasText: 'POST' }).click();
+  };
+
+  const sendRequest = async (page) => {
+    await page.getByTestId('send-arrow-icon').click();
+    await page.getByTestId('response-status-code').waitFor({ state: 'visible', timeout: 15000 });
+  };

Apply similarly across the three tests to replace the repeated steps.

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.

Charset variable in Content-Type header causes incorrectly-formatted POST body

1 participant