Remove check for MQTT path, and normalize code

This commit is contained in:
周子博 2018-09-14 11:29:38 +08:00 committed by Feng Lee
parent 5465b015be
commit 5eb92e37cc
5 changed files with 6 additions and 30 deletions

View File

@ -1207,7 +1207,7 @@ listener.ssl.external.reuseaddr = true
## Examples: 8083, 127.0.0.1:8083, ::1:8083
listener.ws.external = 8083
## Define the path you want to add to the end of the URL
## The path of WebSocket MQTT endpoint
##
## Value: / | /<Any String>
listener.ws.external.mqtt_path = /mqtt
@ -1351,7 +1351,7 @@ listener.ws.external.nodelay = true
## Examples: 8084, 127.0.0.1:8084, ::1:8084
listener.wss.external = 8084
## Define the path you want to add to the end of the URL
## The path of WebSocket MQTT endpoint
##
## Value: / | /<Any String>
listener.wss.external.mqtt_path = /mqtt

View File

@ -1375,8 +1375,8 @@ end}.
end,
LisOpts = fun(Prefix) ->
Filter([{mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
{mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
{max_connections, cuttlefish:conf_get(Prefix ++ ".max_connections", Conf)},
{max_conn_rate, cuttlefish:conf_get(Prefix ++ ".max_conn_rate", Conf, undefined)},
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},

View File

@ -22,12 +22,6 @@
-export([restart_listener/1, restart_listener/3]).
-export([stop_listener/1, stop_listener/3]).
-ifdef(TEST).
-export([mqtt_path/1]).
-endif.
-type(listener() :: {esockd:proto(), esockd:listen_on(), [esockd:option()]}).
%% @doc Start all listeners.
@ -74,12 +68,7 @@ start_http_listener(Start, Name, ListenOn, RanchOpts, Dispatch) ->
Start(Name, with_port(ListenOn, RanchOpts), #{env => #{dispatch => Dispatch}}).
mqtt_path(Options) ->
MQTTPath = proplists:get_value(mqtt_path, Options, "/mqtt"),
case erlang:list_to_bitstring(MQTTPath) of
<<"/">> -> MQTTPath;
<<"/", _/binary>> -> MQTTPath;
_ -> "/mqtt"
end.
proplists:get_value(mqtt_path, Options, "/mqtt").
ranch_opts(Options) ->
NumAcceptors = proplists:get_value(acceptors, Options, 4),

View File

@ -249,13 +249,6 @@ preprocess_properties(Packet = #mqtt_packet{
PState = #pstate{proto_ver = ?MQTT_PROTO_V5, topic_aliases = Aliases}) ->
{Packet, PState#pstate{topic_aliases = maps:put(AliasId, Topic, Aliases)}};
preprocess_properties(Packet = #mqtt_packet{variable = #mqtt_packet_publish{properties = #{'Message-Expiry-Interval' := _Interval}}},
PState = #pstate{proto_ver = ?MQTT_PROTO_V5}) ->
{Packet, PState};
preprocess_properties(Packet = #mqtt_packet{variable = Publish = #mqtt_packet_publish{properties = Properties}},
PState = #pstate{proto_ver = ?MQTT_PROTO_V5}) ->
{Packet#mqtt_packet{variable = Publish#mqtt_packet_publish{properties = maps:put('Message-Expiry-Interval', 0, Properties)}}, PState};
preprocess_properties(Packet, PState) ->
{Packet, PState}.

View File

@ -26,8 +26,7 @@
all() ->
[start_stop_listeners,
restart_listeners,
t_mqtt_path].
restart_listeners].
init_per_suite(Config) ->
NewConfig = generate_config(),
@ -50,11 +49,6 @@ restart_listeners(_) ->
ok = emqx_listeners:restart(),
ok = emqx_listeners:stop().
t_mqtt_path(_) ->
?assertEqual("/test", emqx_listeners:mqtt_path([{mqtt_path, "/test"}])),
?assertEqual("/", emqx_listeners:mqtt_path([{mqtt_path, "/"}])),
?assertEqual("/mqtt", emqx_listeners:mqtt_path([{mqtt_path, "test"}])).
generate_config() ->
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]),