Merge branch 'develop' of github.com:emqtt/emqttd into develop

This commit is contained in:
Feng Lee 2018-01-03 22:49:58 +08:00
commit d26e746f5d
2 changed files with 17 additions and 9 deletions

View File

@ -45,7 +45,7 @@
-export([publish/1, subscribe/1, unsubscribe/1]).
-export([kick_client/1, clean_acl_cache/2]).
-export([kick_client/1, kick_client/2, clean_acl_cache/2, clean_acl_cache/3]).
-export([modify_config/2, modify_config/3, modify_config/4, get_configs/0, get_config/1,
get_plugin_config/1, get_plugin_config/2, modify_plugin_config/2, modify_plugin_config/3]).

View File

@ -45,14 +45,22 @@ handle_request('GET', "/mqtt", Req) ->
Proto = check_protocol_header(Req),
case {is_websocket(Upgrade), Proto} of
{true, "mqtt" ++ _Vsn} ->
{ok, ProtoEnv} = emqttd:env(protocol),
PacketSize = get_value(max_packet_size, ProtoEnv, ?MAX_PACKET_SIZE),
Parser = emqttd_parser:initial_state(PacketSize),
%% Upgrade WebSocket.
{ReentryWs, ReplyChannel} = mochiweb_websocket:upgrade_connection(Req, fun ?MODULE:ws_loop/3),
{ok, ClientPid} = emqttd_ws_client_sup:start_client(self(), Req, ReplyChannel),
ReentryWs(#wsocket_state{peername = Req:get(peername), parser = Parser,
max_packet_size = PacketSize, client_pid = ClientPid});
case Req:get(peername) of
{ok, Peername} ->
{ok, ProtoEnv} = emqttd:env(protocol),
PacketSize = get_value(max_packet_size, ProtoEnv, ?MAX_PACKET_SIZE),
Parser = emqttd_parser:initial_state(PacketSize),
%% Upgrade WebSocket.
{ReentryWs, ReplyChannel} = mochiweb_websocket:upgrade_connection(Req, fun ?MODULE:ws_loop/3),
{ok, ClientPid} = emqttd_ws_client_sup:start_client(self(), Req, ReplyChannel),
ReentryWs(#wsocket_state{peername = Peername,
parser = Parser,
max_packet_size = PacketSize,
client_pid = ClientPid});
{error, Reason} ->
lager:error("Get peername with error ~s", [Reason]),
Req:respond({400, [], <<"Bad Request">>})
end;
{false, _} ->
lager:error("Not WebSocket: Upgrade = ~s", [Upgrade]),
Req:respond({400, [], <<"Bad Request">>});