Skip to content

feat: add default http protocol when URL scheme is missing - #7786

Merged
sid-bruno merged 8 commits into
usebruno:mainfrom
KanhaiyaPandey:feat/default-http-protocol
May 20, 2026
Merged

sid-bruno merged 8 commits into
usebruno:mainfrom
KanhaiyaPandey:feat/default-http-protocol

Conversation

@KanhaiyaPandey

@KanhaiyaPandey KanhaiyaPandey commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7759

JIRA

🚀 Overview

This PR introduces a fallback mechanism to automatically use the http:// protocol when a URL is provided without an explicit scheme.

❗ Problem

Currently, requests like:
GET localhost:8080

result in:
Unsupported protocol localhost:

This creates friction, especially when importing collections from Postman, where such URLs are valid.

✅ Solution

  • Detect URLs without a protocol
  • Automatically prepend http:// before execution
  • Ensure backward compatibility with existing valid URLs

💡 Impact

  • Improves developer experience
  • Reduces manual fixes after importing collections
  • Aligns behavior with tools like Postman

🧪 Testing

  • Verified with URLs:
    • localhost:8080 → http://localhost:8080
    • http://example.com (unchanged)
    • https://example.com (unchanged)

📸 Screenshot

Before

Screenshot 2026-04-17 at 9 56 57 AM

Request:
GET localhost:8080

Error:
Unsupported protocol localhost:

After

Screenshot 2026-04-17 at 9 37 58 AM

Request:
GET localhost:8080

Resolved to:
GET http://localhost:8080 (auto-prepended)

Summary by CodeRabbit

  • Bug Fixes

    • Improved URL scheme detection and normalization so automatic protocol prefixing is more accurate and consistent across CLI and desktop clients; template-variable URLs are preserved unchanged.
  • Tests

    • Expanded URL normalization tests covering schemeless hosts, explicit protocols, and template-variable cases.

Review Change Stack

@coderabbitai

coderabbitai Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a WHATWG-compliant hasExplicitScheme(url) utility, re-exports it from utils, uses it in Electron request normalization (configureRequest) to decide whether to prepend http://, and expands unit/integration tests to cover schemeless, schemed, and template-variable URLs.

Changes

URL Scheme Detection Implementation

Layer / File(s) Summary
hasExplicitScheme utility and unit tests
packages/bruno-common/src/utils/url/index.spec.ts
Adds and tests hasExplicitScheme() imported from ./index, verifying explicit scheme detection, schemeless inputs, and template-variable handling.
URL normalization integration and implementation
packages/bruno-electron/tests/network/index.spec.js, packages/bruno-electron/src/ipc/network/index.js
Replaces local protocol-regex logic with hasExplicitScheme(request.url) in configureRequest, and expands tests to assert http:// is prepended only for schemeless hosts/host:port/path and that schemed or {{...}} template URLs remain unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • usebruno/bruno#6308: Both PRs update URL normalization logic in packages/bruno-electron/src/ipc/network/index.js to change when http:// is prefixed based on explicit scheme detection vs. schemeless/templated URLs.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno
  • Pragadesh44-Bruno

A URL without a scheme took a trip,
Whispered softly, "Add http to my script."
hasExplicitScheme checked clear and true,
Only when it's missing did http come through. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 feature—adding default HTTP protocol when URL scheme is missing—which is the primary focus of all code changes.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #7759: detecting URLs without explicit schemes and prepending http:// before execution, with comprehensive test coverage across CLI, Electron, and common utilities.
Out of Scope Changes check ✅ Passed All changes are in-scope and directly support the core feature—replacing ad-hoc regex with a reusable WHATWG-compliant hasExplicitScheme utility and updating affected modules accordingly.

✏️ 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.

@helloanoop

Copy link
Copy Markdown
Contributor

Thanks @KanhaiyaPandey for the PR. We are looking into this.

@Pragadesh44-Bruno

Copy link
Copy Markdown
Collaborator

@KanhaiyaPandey Thanks for raising this PR. It seems to fix the reported bug. I’ve added tests for the scheme check and refactored protocolRegex into a function called hasExplicitScheme in bruno-common so it can be used across Electron, CLI, and tests.

I also reviewed the scheme syntax in the WHATWG documentation and added relevant case checks. I’ve raised a PR against your repository’s feature branch—could you please take a look and review it?

- Replace regex-based protocol detection with spec-compliant utility
- Ensure correct handling of localhost, IPs, and ports
- Add comprehensive tests for URL normalization
- Centralize logic in bruno-common for reuse across CLI and Electron
@KanhaiyaPandey

Copy link
Copy Markdown
Contributor Author

@KanhaiyaPandey Thanks for raising this PR. It seems to fix the reported bug. I’ve added tests for the scheme check and refactored protocolRegex into a function called hasExplicitScheme in bruno-common so it can be used across Electron, CLI, and tests.

I also reviewed the scheme syntax in the WHATWG documentation and added relevant case checks. I’ve raised a PR against your repository’s feature branch—could you please take a look and review it?

Thanks for the improvements and for taking this forward!

The shift to hasExplicitScheme and aligning with the WHATWG spec makes this much more robust. Really appreciate the added test coverage and the move to bruno-common for reuse across CLI and Electron.

@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-cli/tests/runner/url-protocol-normalization.spec.js (1)

12-14: Local normalizeUrl duplicates prod logic — consider testing the real call site.

The helper reimplements the exact one-liner from packages/bruno-cli/src/runner/run-single-request.js:346-348. If someone changes the production branch (e.g., adds https:// fallback, or gates on request.url.startsWith('{{')), these tests will keep passing while the real code regresses.

Since hasExplicitScheme is already covered directly in packages/bruno-electron/tests/network/index.spec.js, this suite's value is in exercising the CLI path. Either (a) import and invoke the real normalization from run-single-request.js, or (b) rename the suite to make clear it's unit-testing hasExplicitScheme — not "run-single-request" normalization as the describe block currently claims.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-cli/tests/runner/url-protocol-normalization.spec.js` around
lines 12 - 14, The test currently reimplements normalizeUrl and duplicates
production logic (normalizeUrl and hasExplicitScheme); instead either (A) remove
the local normalizeUrl and import the real normalization function from
run-single-request.js (use the module export for normalizeUrl or the exported
normalization helper used by runSingleRequest) and call that in the tests so the
CLI path is exercised, or (B) if you want a pure unit test for hasExplicitScheme
only, rename the describe block to clearly state it is testing hasExplicitScheme
and move the local helper into that namespaced suite; update test
imports/assertions accordingly to reference normalizeUrl and hasExplicitScheme
by their actual exported names.
🤖 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-electron/tests/network/index.spec.js`:
- Around line 40-51: The two tests are tautological because they only assert
String.prototype.startsWith rather than Bruno behaviour; replace them with
integration assertions that call configureRequest (and/or the hasExplicitScheme
logic) using the inputs '{{baseUrl}}' and '{{baseUrl}}/api/v1' and assert the
real observable behaviour: e.g., that configureRequest returns a request with
the same template URL (no scheme injection) and that hasExplicitScheme is false
(or that no scheme is added), or simply delete the two startsWith tests if you
prefer to remove redundancy; locate symbols configureRequest and
hasExplicitScheme in the test suite to implement the change.

---

Nitpick comments:
In `@packages/bruno-cli/tests/runner/url-protocol-normalization.spec.js`:
- Around line 12-14: The test currently reimplements normalizeUrl and duplicates
production logic (normalizeUrl and hasExplicitScheme); instead either (A) remove
the local normalizeUrl and import the real normalization function from
run-single-request.js (use the module export for normalizeUrl or the exported
normalization helper used by runSingleRequest) and call that in the tests so the
CLI path is exercised, or (B) if you want a pure unit test for hasExplicitScheme
only, rename the describe block to clearly state it is testing hasExplicitScheme
and move the local helper into that namespaced suite; update test
imports/assertions accordingly to reference normalizeUrl and hasExplicitScheme
by their actual exported names.
🪄 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: d217acf2-2441-4ba7-9cdf-abd2a42a930d

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb5c1a and 7174ff3.

📒 Files selected for processing (6)
  • packages/bruno-cli/src/runner/run-single-request.js
  • packages/bruno-cli/tests/runner/url-protocol-normalization.spec.js
  • packages/bruno-common/src/utils/index.ts
  • packages/bruno-common/src/utils/url/index.ts
  • packages/bruno-electron/src/ipc/network/index.js
  • packages/bruno-electron/tests/network/index.spec.js
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-common/src/utils/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/bruno-cli/src/runner/run-single-request.js
  • packages/bruno-electron/src/ipc/network/index.js

@sid-bruno sid-bruno added the adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers label May 20, 2026
sid-bruno
sid-bruno previously approved these changes May 20, 2026
@sid-bruno
sid-bruno enabled auto-merge (squash) May 20, 2026 06:20
@sid-bruno
sid-bruno disabled auto-merge May 20, 2026 15:05
@sid-bruno
sid-bruno merged commit c5528a7 into usebruno:main May 20, 2026
16 of 19 checks passed
lyh543 pushed a commit to lyh543/bruno that referenced this pull request May 22, 2026
jattsson pushed a commit to jattsson/bruno that referenced this pull request May 26, 2026
sharan-bruno pushed a commit to sharan-bruno/bruno that referenced this pull request Jun 4, 2026
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/L

Projects

None yet

6 participants