Remove check for MQTT path, and normalize code
This commit is contained in:
parent
a38d357847
commit
c7928235c3
|
@ -1207,7 +1207,7 @@ listener.ssl.external.reuseaddr = true
|
||||||
## Examples: 8083, 127.0.0.1:8083, ::1:8083
|
## Examples: 8083, 127.0.0.1:8083, ::1:8083
|
||||||
listener.ws.external = 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>
|
## Value: / | /<Any String>
|
||||||
listener.ws.external.mqtt_path = /mqtt
|
listener.ws.external.mqtt_path = /mqtt
|
||||||
|
@ -1351,7 +1351,7 @@ listener.ws.external.nodelay = true
|
||||||
## Examples: 8084, 127.0.0.1:8084, ::1:8084
|
## Examples: 8084, 127.0.0.1:8084, ::1:8084
|
||||||
listener.wss.external = 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>
|
## Value: / | /<Any String>
|
||||||
listener.wss.external.mqtt_path = /mqtt
|
listener.wss.external.mqtt_path = /mqtt
|
||||||
|
|
|
@ -1375,8 +1375,8 @@ end}.
|
||||||
end,
|
end,
|
||||||
|
|
||||||
LisOpts = fun(Prefix) ->
|
LisOpts = fun(Prefix) ->
|
||||||
Filter([{mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
|
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
|
||||||
{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_connections, cuttlefish:conf_get(Prefix ++ ".max_connections", Conf)},
|
||||||
{max_conn_rate, cuttlefish:conf_get(Prefix ++ ".max_conn_rate", Conf, undefined)},
|
{max_conn_rate, cuttlefish:conf_get(Prefix ++ ".max_conn_rate", Conf, undefined)},
|
||||||
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},
|
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},
|
||||||
|
|
|
@ -22,12 +22,6 @@
|
||||||
-export([restart_listener/1, restart_listener/3]).
|
-export([restart_listener/1, restart_listener/3]).
|
||||||
-export([stop_listener/1, stop_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()]}).
|
-type(listener() :: {esockd:proto(), esockd:listen_on(), [esockd:option()]}).
|
||||||
|
|
||||||
%% @doc Start all listeners.
|
%% @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}}).
|
Start(Name, with_port(ListenOn, RanchOpts), #{env => #{dispatch => Dispatch}}).
|
||||||
|
|
||||||
mqtt_path(Options) ->
|
mqtt_path(Options) ->
|
||||||
MQTTPath = proplists:get_value(mqtt_path, Options, "/mqtt"),
|
proplists:get_value(mqtt_path, Options, "/mqtt").
|
||||||
case erlang:list_to_bitstring(MQTTPath) of
|
|
||||||
<<"/">> -> MQTTPath;
|
|
||||||
<<"/", _/binary>> -> MQTTPath;
|
|
||||||
_ -> "/mqtt"
|
|
||||||
end.
|
|
||||||
|
|
||||||
ranch_opts(Options) ->
|
ranch_opts(Options) ->
|
||||||
NumAcceptors = proplists:get_value(acceptors, Options, 4),
|
NumAcceptors = proplists:get_value(acceptors, Options, 4),
|
||||||
|
|
|
@ -249,13 +249,6 @@ preprocess_properties(Packet = #mqtt_packet{
|
||||||
PState = #pstate{proto_ver = ?MQTT_PROTO_V5, topic_aliases = Aliases}) ->
|
PState = #pstate{proto_ver = ?MQTT_PROTO_V5, topic_aliases = Aliases}) ->
|
||||||
{Packet, PState#pstate{topic_aliases = maps:put(AliasId, Topic, 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) ->
|
preprocess_properties(Packet, PState) ->
|
||||||
{Packet, PState}.
|
{Packet, PState}.
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
[start_stop_listeners,
|
[start_stop_listeners,
|
||||||
restart_listeners,
|
restart_listeners].
|
||||||
t_mqtt_path].
|
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
NewConfig = generate_config(),
|
NewConfig = generate_config(),
|
||||||
|
@ -50,11 +49,6 @@ restart_listeners(_) ->
|
||||||
ok = emqx_listeners:restart(),
|
ok = emqx_listeners:restart(),
|
||||||
ok = emqx_listeners:stop().
|
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() ->
|
generate_config() ->
|
||||||
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
||||||
Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]),
|
Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]),
|
||||||
|
|
Loading…
Reference in New Issue