Skip to content

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

Open
KanhaiyaPandey wants to merge 4 commits intousebruno:mainfrom
KanhaiyaPandey:feat/default-http-protocol
Open

feat: add default http protocol when URL scheme is missing#7786
KanhaiyaPandey wants to merge 4 commits intousebruno:mainfrom
KanhaiyaPandey:feat/default-http-protocol

Conversation

@KanhaiyaPandey
Copy link
Copy Markdown

@KanhaiyaPandey KanhaiyaPandey commented Apr 17, 2026

Fixes #7759

🚀 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:8080http://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 protocol detection: bare hostnames, IPs, host:port, and host-with-path inputs (e.g., localhost, localhost:8080, 127.0.0.1:3000, example.com/api) are correctly treated as missing a scheme and default to HTTP; URLs with explicit schemes (http/https/ftp/ws/wss and custom schemes) remain unchanged.
  • Tests
    • Added comprehensive tests validating URL normalization and that template variables bypass scheme injection.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

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: 2dd8afde-ab12-4ebb-9793-345059a63eb8

📥 Commits

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

📒 Files selected for processing (1)
  • packages/bruno-electron/tests/network/index.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-electron/tests/network/index.spec.js

Walkthrough

Replaced a permissive local protocol regex with a new hasExplicitScheme(url) utility used by CLI and Electron request normalization; shorthand URLs (e.g., localhost:8080) are now detected as schemeless and prefixed with http://. Added unit/integration tests and re-exported the utility from common utils.

Changes

Cohort / File(s) Summary
Core URL utility
packages/bruno-common/src/utils/url/index.ts, packages/bruno-common/src/utils/index.ts
Added hasExplicitScheme(url: string): boolean and re-exported it from the utils entrypoint.
Runtime URL normalization
packages/bruno-cli/src/runner/run-single-request.js, packages/bruno-electron/src/ipc/network/index.js
Replaced local protocolRegex heuristic with hasExplicitScheme(request.url) when deciding to prepend http://; preserve templated variables (e.g., {{...}}) and skip prefixing in those cases.
Tests
packages/bruno-cli/tests/runner/url-protocol-normalization.spec.js, packages/bruno-electron/tests/network/index.spec.js
Added/updated unit and integration tests covering schemeless inputs (hosts, IPs, host:port, paths), explicit schemes (http(s), ftp, ws, custom), and template-variable bypass behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

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

Poem

🌐 A tiny scheme-seeking light,
When hosts arrive without their might,
http:// slips in to guide the way,
Tests nod yes and let requests sway,
Short URLs now set off bright.

🚥 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 change: adding default HTTP protocol when URL scheme is missing.
Linked Issues check ✅ Passed The PR fully addresses issue #7759 by implementing HTTP protocol auto-prepend for URLs without explicit schemes, with comprehensive tests and WHATWG-compliant scheme detection.
Out of Scope Changes check ✅ Passed All changes directly support the core objective: URL scheme detection utility, integration into CLI/Electron runners, and test coverage. No extraneous modifications detected.

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

…ocol normalization

Co-authored-by: KanhaiyaPandey <kanhaiyapandey2232@gmail.com>
@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
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.

Copy link
Copy Markdown
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: 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

Comment thread packages/bruno-electron/tests/network/index.spec.js
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.

Use http:// protocol if not defined

4 participants