Skip to content

fix(websocket): path handling when merging template & target URLs#7290

Merged
dwisiswant0 merged 1 commit intodevfrom
5028-fix-websocket-double-path
Mar 24, 2026
Merged

fix(websocket): path handling when merging template & target URLs#7290
dwisiswant0 merged 1 commit intodevfrom
5028-fix-websocket-double-path

Conversation

@Mzack9999
Copy link
Member

@Mzack9999 Mzack9999 commented Mar 23, 2026

Proposed changes

Close #5028

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket URL path handling to preserve custom paths instead of forcing automatic path joining, resulting in more predictable connection behavior.

@Mzack9999 Mzack9999 self-assigned this Mar 23, 2026
@auto-assign auto-assign bot requested a review from dogancanbakir March 23, 2026 20:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

Walkthrough

Fixed a double path concatenation bug in WebSocket URL handling where paths were being incorrectly joined twice. Now the path is only replaced when the base path is empty or root (/); otherwise the original path is preserved. Added comprehensive test coverage for address resolution and WebSocket URL parsing.

Changes

Cohort / File(s) Summary
WebSocket Path Resolution Fix
pkg/protocols/websocket/websocket.go
Removed forced path joining logic. Changed path.Join(parsedAddress.Path, parsed.Path) to conditionally override parsedAddress.Path only when it's empty or /, preventing double path concatenation in dial addresses.
WebSocket Testing Suite
pkg/protocols/websocket/websocket_test.go
Added helper function and two comprehensive test suites: TestAddressResolution validates path resolution across various scenarios (preserved paths, deep paths, trailing slashes, ports, query strings); TestGetAddress validates host extraction from ws/wss URLs and error handling for invalid schemes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tangled path that doubled and twisted round,
Now resolves with grace to true ground,
Tests stand guard, both swift and sure,
WebSocket connections now pure! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes the double-path concatenation issue [#5028] by modifying path-joining logic, but does not address the binary frame opcode requirement from the linked issue. Replace ws.OpText with ws.OpBinary or add configurable type support to handle binary websocket payloads as requested in issue #5028.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Out of Scope Changes check ✅ Passed All changes are directly related to addressing the double-path bug from issue #5028; the addition of comprehensive tests is appropriate in-scope support.
Title check ✅ Passed The PR title accurately describes the main change: fixing path handling when merging template and target URLs, which directly addresses the double-path concatenation issue documented in the PR objectives.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 5028-fix-websocket-double-path

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.

Caution

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

⚠️ Outside diff range comments (1)
pkg/protocols/websocket/websocket.go (1)

311-312: ⚠️ Potential issue | 🟠 Major

Binary websocket writes remain blocked by hardcoded text opcode.

Line 311 always uses ws.OpText, preventing binary payload transmission from templates. The Input struct (lines 78–92) has no frame-type selector field, and there are no send-path binary tests. Issue #5028 is only partially addressed.

💡 Suggested fix (add explicit frame type with backward-compatible default)
 type Input struct {
@@
 	Data string `yaml:"data,omitempty" json:"data,omitempty" jsonschema:"title=data to send as input,description=Data is the data to send as the input"`
+	// Type is the websocket frame type for this input (text or binary).
+	// examples:
+	//   - value: "\"text\""
+	//   - value: "\"binary\""
+	Type string `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"title=websocket frame type,description=Frame type for payload,enum=text,enum=binary"`
@@
-		err = wsutil.WriteClientMessage(conn, ws.OpText, finalData)
+		opcode := ws.OpText
+		if strings.EqualFold(req.Type, "binary") {
+			opcode = ws.OpBinary
+		}
+		err = wsutil.WriteClientMessage(conn, opcode, finalData)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/protocols/websocket/websocket.go` around lines 311 - 312, The write path
always uses ws.OpText (wsutil.WriteClientMessage(conn, ws.OpText, finalData)),
blocking binary frames; add a frame-type selector to the Input struct (e.g.,
FrameType string or FrameOp int) with a backward-compatible default of text,
update the send logic in the function that writes finalData to choose
ws.OpBinary when the Input.FrameType indicates binary (otherwise use ws.OpText),
and add/adjust tests to cover binary payload transmission through
wsutil.WriteClientMessage and the new Input frame selection behavior.
🧹 Nitpick comments (1)
pkg/protocols/websocket/websocket_test.go (1)

13-26: Avoid duplicating production path-resolution logic inside test helper.

resolveAddress mirrors implementation logic line-for-line, so the test can pass even if both are wrong in the same way. Prefer calling a shared exported/internal resolver from websocket.go to keep a single source of truth.

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

In `@pkg/protocols/websocket/websocket_test.go` around lines 13 - 26, The test
helper duplicates production logic in resolveAddress; remove this local helper
and call the shared resolver implemented in websocket.go (e.g., the
exported/internal ResolveAddress or the package-level resolveAddress in
websocket.go) so the test uses the same implementation as production; update
imports/tests to reference that function, delete the duplicate resolveAddress in
websocket_test.go, and adjust any call sites in the tests to use the shared
symbol (ResolveAddress/resolveAddress) so there is a single source of truth for
path-resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/protocols/websocket/websocket.go`:
- Around line 311-312: The write path always uses ws.OpText
(wsutil.WriteClientMessage(conn, ws.OpText, finalData)), blocking binary frames;
add a frame-type selector to the Input struct (e.g., FrameType string or FrameOp
int) with a backward-compatible default of text, update the send logic in the
function that writes finalData to choose ws.OpBinary when the Input.FrameType
indicates binary (otherwise use ws.OpText), and add/adjust tests to cover binary
payload transmission through wsutil.WriteClientMessage and the new Input frame
selection behavior.

---

Nitpick comments:
In `@pkg/protocols/websocket/websocket_test.go`:
- Around line 13-26: The test helper duplicates production logic in
resolveAddress; remove this local helper and call the shared resolver
implemented in websocket.go (e.g., the exported/internal ResolveAddress or the
package-level resolveAddress in websocket.go) so the test uses the same
implementation as production; update imports/tests to reference that function,
delete the duplicate resolveAddress in websocket_test.go, and adjust any call
sites in the tests to use the shared symbol (ResolveAddress/resolveAddress) so
there is a single source of truth for path-resolution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cec8e0a4-ae0f-4aa2-8267-2ca133a33581

📥 Commits

Reviewing files that changed from the base of the PR and between e4edd5a and f50e54f.

📒 Files selected for processing (2)
  • pkg/protocols/websocket/websocket.go
  • pkg/protocols/websocket/websocket_test.go

@dwisiswant0 dwisiswant0 changed the title fixing double path fix(websocket): path handling when merging template & target URLs Mar 24, 2026
@dwisiswant0 dwisiswant0 merged commit 233af2c into dev Mar 24, 2026
20 checks passed
@dwisiswant0 dwisiswant0 deleted the 5028-fix-websocket-double-path branch March 24, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please fix Websocket impl.

2 participants