Skip to content

Commit dbe973a

Browse files
lukebakkenmergify[bot]
authored andcommitted
Support mqttv3.1 WebSocket subprotocol in addition to mqtt
Addresses #15001 The Web MQTT handler only accepts the `mqtt` WebSocket subprotocol, rejecting clients that request `mqttv3.1`. This prevents some MQTT clients from establishing WebSocket connections. This change updates the protocol negotiation to accept either `mqtt` or `mqttv3.1` subprotocols. The handler uses `lists:search/2` to find the first matching protocol and echoes that exact value back in the `sec-websocket-protocol` response header, ensuring proper protocol negotiation with the client. (cherry picked from commit 12a6645) (cherry picked from commit 89df4a2)
1 parent b85deb1 commit dbe973a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_handler.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ init(Req, Opts) ->
7575
undefined ->
7676
no_supported_sub_protocol(undefined, Req);
7777
Protocol ->
78-
case lists:member(<<"mqtt">>, Protocol) of
78+
case lists:search(fun(P) -> P =:= <<"mqtt">> orelse P =:= <<"mqttv3.1">> end, Protocol) of
7979
false ->
8080
no_supported_sub_protocol(Protocol, Req);
81-
true ->
82-
Req1 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, <<"mqtt">>, Req),
81+
{value, MatchedProtocol} ->
82+
Req1 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>, MatchedProtocol, Req),
8383
State = #state{socket = maps:get(proxy_header, Req, undefined),
8484
stats_timer = rabbit_event:init_stats_timer()},
8585
WsOpts0 = proplists:get_value(ws_opts, Opts, #{}),

0 commit comments

Comments
 (0)