Skip to content

Add Sec-WebSocket-Protocol to the HTTP header#79

Merged
Gsantomaggio merged 2 commits intomainfrom
update/web_sockets_tanzu
Jan 21, 2026
Merged

Add Sec-WebSocket-Protocol to the HTTP header#79
Gsantomaggio merged 2 commits intomainfrom
update/web_sockets_tanzu

Conversation

@Gsantomaggio
Copy link
Copy Markdown
Member

@Gsantomaggio Gsantomaggio commented Jan 21, 2026

This pull request adds support for the AMQP WebSocket subprotocol by including the Sec-WebSocket-Protocol header in WebSocket connections, and provides a complete example demonstrating AMQP 1.0 over WebSockets.

Changes:

  • Added Sec-WebSocket-Protocol: amqp header to WebSocket connection initialization
  • Created a comprehensive WebSocket example with queue declaration, message publishing, and consumption
  • Added documentation for setting up and running the WebSocket example

Complete: #78

add example

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for the AMQP WebSocket subprotocol by including the Sec-WebSocket-Protocol header in WebSocket connections, and provides a complete example demonstrating AMQP 1.0 over WebSockets.

Changes:

  • Added Sec-WebSocket-Protocol: amqp header to WebSocket connection initialization
  • Created a comprehensive WebSocket example with queue declaration, message publishing, and consumption
  • Added documentation for setting up and running the WebSocket example

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
pkg/rabbitmqamqp/amqp_connection.go Adds Sec-WebSocket-Protocol header to specify AMQP subprotocol for WebSocket connections
docs/examples/web_sockets/web_sockets.go New example demonstrating full AMQP workflow over WebSocket protocol
docs/examples/web_sockets/README.md Documentation for WebSocket example including setup requirements and alternatives
docs/examples/README.md Updates examples index to include new WebSocket example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// The example is demonstrating how to connect to RabbitMQ using AMQP 1.0 over WebSocket protocol,
// declare a queue, publish a message to it, and then consume that message.
// AMQP 1.0 over WebSocket documentation: https://www.rabbitmq.com/blog/2025/04/16/amqp-websocket
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples//web_sockets/web_sockets.go
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

There is an extra forward slash in the example path. It should be "/tree/main/docs/examples/web_sockets/" instead of "/tree/main/docs/examples//web_sockets/".

Suggested change
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples//web_sockets/web_sockets.go
// example path: https://github.com/rabbitmq/rabbitmq-amqp-go-client/tree/main/docs/examples/web_sockets/web_sockets.go

Copilot uses AI. Check for mistakes.
Comment thread pkg/rabbitmqamqp/amqp_connection.go Outdated
Comment on lines +12 to +13
- A vhost called `ws` configured for WebSocket connections.
- A user `rabbit` pwd `rabbit` with access to the `ws` vhost.
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The documentation mentions a vhost called 'ws' is required (line 12), but the example code uses the default vhost (no vhost specified in the connection string on line 17 of web_sockets.go). This inconsistency between documentation and code will confuse users. Either update the connection string to include the 'ws' vhost or correct the documentation to match the example.

Suggested change
- A vhost called `ws` configured for WebSocket connections.
- A user `rabbit` pwd `rabbit` with access to the `ws` vhost.
- A vhost (for example the default `/`) configured for WebSocket connections.
- A user `rabbit` pwd `rabbit` with access to that vhost.

Copilot uses AI. Check for mistakes.
Comment thread pkg/rabbitmqamqp/amqp_connection.go Outdated
Comment thread pkg/rabbitmqamqp/amqp_connection.go Outdated
Comment on lines +764 to +765
// add sec-websocket-protocol amqp
headers.Add("Sec-WebSocket-Protocol", "amqp")
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The new Sec-WebSocket-Protocol header addition lacks test coverage. Since other connection functionality in amqp_connection_test.go has comprehensive test coverage, this new behavior should also be tested. Consider adding a test case that verifies the header is properly set in the returned http.Header, both with and without authentication credentials.

Copilot uses AI. Check for mistakes.
Comment thread docs/examples/web_sockets/README.md
add example

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
@Gsantomaggio Gsantomaggio merged commit d21f0c8 into main Jan 21, 2026
3 of 4 checks passed
@Gsantomaggio Gsantomaggio deleted the update/web_sockets_tanzu branch January 21, 2026 12:21
@Gsantomaggio Gsantomaggio added this to the 0.5.0 milestone Jan 21, 2026
@Gsantomaggio Gsantomaggio added the enhancement New feature or request label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants