Merge pull request #1060 from emqtt/develop
Add a 'websocket_protocol_header' option to handle WebSocket connection from WeChat
This commit is contained in:
commit
b98ea3ec8e
|
@ -119,6 +119,9 @@ mqtt.max_clientid_len = 1024
|
|||
## Max Packet Size Allowed, 64K by default.
|
||||
mqtt.max_packet_size = 64KB
|
||||
|
||||
## Check Websocket Protocol Header. Enum: on, off
|
||||
mqtt.websocket_protocol_header = on
|
||||
|
||||
##--------------------------------------------------------------------
|
||||
## MQTT Connection
|
||||
##--------------------------------------------------------------------
|
||||
|
|
|
@ -346,6 +346,11 @@ end}.
|
|||
{max_packet_size, cuttlefish:conf_get("mqtt.max_packet_size", Conf)}]
|
||||
end}.
|
||||
|
||||
{mapping, "mqtt.websocket_protocol_header", "emqttd.websocket_protocol_header", [
|
||||
{default, on},
|
||||
{datatype, flag}
|
||||
]}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% MQTT Connection
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -59,7 +59,7 @@ handle_request('POST', "/mqtt/publish", Req) ->
|
|||
handle_request('GET', "/mqtt", Req) ->
|
||||
lager:info("WebSocket Connection from: ~s", [Req:get(peer)]),
|
||||
Upgrade = Req:get_header_value("Upgrade"),
|
||||
Proto = Req:get_header_value("Sec-WebSocket-Protocol"),
|
||||
Proto = check_protocol_header(Req),
|
||||
case {is_websocket(Upgrade), Proto} of
|
||||
{true, "mqtt" ++ _Vsn} ->
|
||||
emqttd_ws:handle_request(Req);
|
||||
|
@ -83,6 +83,18 @@ handle_request(Method, Path, Req) ->
|
|||
lager:error("Unexpected HTTP Request: ~s ~s", [Method, Path]),
|
||||
Req:not_found().
|
||||
|
||||
check_protocol_header(Req) ->
|
||||
case emqttd:env(websocket_protocol_header, false) of
|
||||
true -> get_protocol_header(Req);
|
||||
false -> "mqtt-v3.1.1"
|
||||
end.
|
||||
|
||||
get_protocol_header(Req) ->
|
||||
case Req:get_header_value("EMQ-WebSocket-Protocol") of
|
||||
undefined -> Req:get_header_value("Sec-WebSocket-Protocol");
|
||||
Proto -> Proto
|
||||
end.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% HTTP Publish
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue