Skip to content

fix: use nats.ProxyPath when server is a websocket connection with a path - #1672

Open
joeriddles wants to merge 4 commits into
nats-io:mainfrom
joeriddles:fix-ws-path
Open

fix: use nats.ProxyPath when server is a websocket connection with a path#1672
joeriddles wants to merge 4 commits into
nats-io:mainfrom
joeriddles:fix-ws-path

Conversation

@joeriddles

Copy link
Copy Markdown
Contributor

Fix WebSocket connections when the URL has a path.

This is an alternative fix to nats-io/nats.go#2092.

# before
❯ nats -s 'ws://localhost:8080/api/cp-nats/' pub 'xyz' test
nats: error: invalid websocket connection

# after
❯ nats -s 'ws://localhost:8080/api/cp-nats/' pub 'xyz' test
10:22:37 Published 4 bytes to "xyz"

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d22953689

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/util.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 985ccdc534

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/util.go

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a473d11542

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/util.go Outdated
updated = append(updated, s)
continue
}
if (u.Scheme == "ws" || u.Scheme == "wss") && u.Path != "" && u.Path != "/" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject WebSocket entries that would inherit the wrong path

When a server list mixes a WebSocket URL with a proxy path and one that uses the default path, e.g. ws://a.example/nats,ws://b.example, this condition ignores the default-path URL while nats.ProxyPath(proxyPath) is still appended globally for the whole connection. If the client initially selects or reconnects to ws://b.example, it will handshake on /nats instead of /, so a valid fallback server can fail or route to the wrong backend; the extraction should also reject/handle ws/wss URLs whose request target is the default once any non-default proxy path is present.

Useful? React with 👍 / 👎.

Comment thread cli/util.go
return nil, err
}
if proxyPath != "" {
copts = append(copts, nats.ProxyPath(proxyPath))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this would be a natscontext behaviour instead wouldn't it? It handles the core connection ops setting and parsing etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I created a PR in jsm.go: nats-io/jsm.go#813

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2e7d6b560

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/util.go
continue
}
isWS := u.Scheme == "ws" || u.Scheme == "wss"
if isWS && u.Path != "" && u.Path != "/" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve query-only WebSocket request targets

For WebSocket URLs whose request target is the root plus a query, such as ws://proxy.example/?tenant=a, u.RequestURI() is /?tenant=a but this condition treats u.Path == "/" as the default path and leaves the URL unconverted. The nats.go WebSocket handshake only uses nats.ProxyPath for the request target, so the query is dropped and proxies that route or authorize on that query still receive just /; handle non-empty RawQuery/ForceQuery as a proxy path even when the path is /.

Useful? React with 👍 / 👎.

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.

2 participants