Skip to content

Add support for Sec-WebSocket-Protocol#1621

Merged
spuun merged 1 commit intomainfrom
add-sec-websocket-protocol
Jan 20, 2026
Merged

Add support for Sec-WebSocket-Protocol#1621
spuun merged 1 commit intomainfrom
add-sec-websocket-protocol

Conversation

@spuun
Copy link
Copy Markdown
Member

@spuun spuun commented Jan 16, 2026

Add support for Sec-WebSocket-Protocol header

Implements RFC 6455 sub-protocol negotiation for WebSocket connections, allowing clients to specify whether they want to use AMQP or MQTT via the Sec-WebSocket-Protocol header during the WebSocket handshake.

Changes:

  • Parse Sec-WebSocket-Protocol header values starting with "amqp" or "mqtt" to determine protocol
  • Respond with the chosen protocol in the handshake response
  • Maintain backward compatibility by falling back to path-based detection (/mqtt, /ws/mqtt)
  • Default to AMQP when no protocol is specified
  • Add comprehensive test coverage for both protocols with various header values

This allows WebSocket clients to properly negotiate the protocol according to IANA registered WebSocket sub-protocol names.

Fixes #1615

@spuun spuun requested a review from a team as a code owner January 16, 2026 14:36
@spuun spuun merged commit e39ef94 into main Jan 20, 2026
14 of 18 checks passed
@spuun spuun deleted the add-sec-websocket-protocol branch January 20, 2026 07:27
spuun added a commit that referenced this pull request Jan 23, 2026
…er (#1637)

This fixes some parts that #1621 missed.

The specs added in #1621 did only verify that the websocket handler
picked the right client handler based on `Sec-WebSocket-Protocol`. What
they didn't verify was if `Sec-WebSocket-Protocol` was sent back to the
client.

Because of how Crystal's `HTTP::WebSocketHandler` and
`HTTP::Server:Response#upgrade` works I just copied
`HTTP::WebSocketHandler` to make my own fixed version.
crystal-lang/crystal#16574 would fix this in the
stdlib.
viktorerlingsson pushed a commit that referenced this pull request Jan 28, 2026
Add support for Sec-WebSocket-Protocol header

Implements RFC 6455 sub-protocol negotiation for WebSocket connections,
allowing clients to specify whether they want to use AMQP or MQTT via
the `Sec-WebSocket-Protocol` header during the WebSocket handshake.

Changes:
- Parse `Sec-WebSocket-Protocol` header values starting with "amqp" or
"mqtt" to determine protocol
- Respond with the chosen protocol in the handshake response
- Maintain backward compatibility by falling back to path-based
detection (`/mqtt`, `/ws/mqtt`)
- Default to AMQP when no protocol is specified
- Add comprehensive test coverage for both protocols with various header
values

This allows WebSocket clients to properly negotiate the protocol
according to IANA registered WebSocket sub-protocol names.

Fixes #1615
viktorerlingsson pushed a commit that referenced this pull request Jan 28, 2026
…er (#1637)

This fixes some parts that #1621 missed.

The specs added in #1621 did only verify that the websocket handler
picked the right client handler based on `Sec-WebSocket-Protocol`. What
they didn't verify was if `Sec-WebSocket-Protocol` was sent back to the
client.

Because of how Crystal's `HTTP::WebSocketHandler` and
`HTTP::Server:Response#upgrade` works I just copied
`HTTP::WebSocketHandler` to make my own fixed version.
crystal-lang/crystal#16574 would fix this in the
stdlib.
kickster97 pushed a commit that referenced this pull request Feb 6, 2026
Add support for Sec-WebSocket-Protocol header

Implements RFC 6455 sub-protocol negotiation for WebSocket connections,
allowing clients to specify whether they want to use AMQP or MQTT via
the `Sec-WebSocket-Protocol` header during the WebSocket handshake.

Changes:
- Parse `Sec-WebSocket-Protocol` header values starting with "amqp" or
"mqtt" to determine protocol
- Respond with the chosen protocol in the handshake response
- Maintain backward compatibility by falling back to path-based
detection (`/mqtt`, `/ws/mqtt`)
- Default to AMQP when no protocol is specified
- Add comprehensive test coverage for both protocols with various header
values

This allows WebSocket clients to properly negotiate the protocol
according to IANA registered WebSocket sub-protocol names.

Fixes #1615
kickster97 pushed a commit that referenced this pull request Feb 6, 2026
…er (#1637)

This fixes some parts that #1621 missed.

The specs added in #1621 did only verify that the websocket handler
picked the right client handler based on `Sec-WebSocket-Protocol`. What
they didn't verify was if `Sec-WebSocket-Protocol` was sent back to the
client.

Because of how Crystal's `HTTP::WebSocketHandler` and
`HTTP::Server:Response#upgrade` works I just copied
`HTTP::WebSocketHandler` to make my own fixed version.
crystal-lang/crystal#16574 would fix this in the
stdlib.
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.

Set Sec-WebSocket-Protocol

3 participants