Merge branch 'develop' of github.com:emqtt/emqttd into develop
This commit is contained in:
commit
d26e746f5d
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
-export([publish/1, subscribe/1, unsubscribe/1]).
|
-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,
|
-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]).
|
get_plugin_config/1, get_plugin_config/2, modify_plugin_config/2, modify_plugin_config/3]).
|
||||||
|
|
|
@ -45,14 +45,22 @@ handle_request('GET', "/mqtt", Req) ->
|
||||||
Proto = check_protocol_header(Req),
|
Proto = check_protocol_header(Req),
|
||||||
case {is_websocket(Upgrade), Proto} of
|
case {is_websocket(Upgrade), Proto} of
|
||||||
{true, "mqtt" ++ _Vsn} ->
|
{true, "mqtt" ++ _Vsn} ->
|
||||||
|
case Req:get(peername) of
|
||||||
|
{ok, Peername} ->
|
||||||
{ok, ProtoEnv} = emqttd:env(protocol),
|
{ok, ProtoEnv} = emqttd:env(protocol),
|
||||||
PacketSize = get_value(max_packet_size, ProtoEnv, ?MAX_PACKET_SIZE),
|
PacketSize = get_value(max_packet_size, ProtoEnv, ?MAX_PACKET_SIZE),
|
||||||
Parser = emqttd_parser:initial_state(PacketSize),
|
Parser = emqttd_parser:initial_state(PacketSize),
|
||||||
%% Upgrade WebSocket.
|
%% Upgrade WebSocket.
|
||||||
{ReentryWs, ReplyChannel} = mochiweb_websocket:upgrade_connection(Req, fun ?MODULE:ws_loop/3),
|
{ReentryWs, ReplyChannel} = mochiweb_websocket:upgrade_connection(Req, fun ?MODULE:ws_loop/3),
|
||||||
{ok, ClientPid} = emqttd_ws_client_sup:start_client(self(), Req, ReplyChannel),
|
{ok, ClientPid} = emqttd_ws_client_sup:start_client(self(), Req, ReplyChannel),
|
||||||
ReentryWs(#wsocket_state{peername = Req:get(peername), parser = Parser,
|
ReentryWs(#wsocket_state{peername = Peername,
|
||||||
max_packet_size = PacketSize, client_pid = ClientPid});
|
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, _} ->
|
{false, _} ->
|
||||||
lager:error("Not WebSocket: Upgrade = ~s", [Upgrade]),
|
lager:error("Not WebSocket: Upgrade = ~s", [Upgrade]),
|
||||||
Req:respond({400, [], <<"Bad Request">>});
|
Req:respond({400, [], <<"Bad Request">>});
|
||||||
|
|
Loading…
Reference in New Issue