Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable websocket path #1814

Merged
merged 10 commits into from Sep 14, 2018

Conversation

@tigercl
Copy link
Collaborator

tigercl commented Sep 12, 2018

Issue: #1809

tigercl added 5 commits Sep 8, 2018
emqx30
@emqplus emqplus self-requested a review Sep 13, 2018
@emqplus emqplus self-assigned this Sep 13, 2018
## Whether the client must include "mqtt" in the list of WebSocket Sub Protocols it offers
##
## Value: true | false
listener.ws.external.standard_mqtt = true

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

listener.ws.external.mqtt_path = /mqtt

## Whether the client must include "mqtt" in the list of WebSocket Sub Protocols it offers
##
## Value: true | false
listener.wss.external.standard_mqtt = true

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

listener.ws.external.mqtt_path = /mqtt

{mapping, "listener.ws.$name.standard_mqtt", "emqx.listeners", [
{default, true},
{datatype, {enum, [true, false]}}
]}.

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
{mapping, "listener.ws.$name.mqtt_path", "emqx.listeners", [
   {default, "/mqtt"},
   {datatype, string}
 ]}.
{default, true},
{datatype, {enum, [true, false]}}
]}.

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
{mapping, "listener.wss.$name.mqtt_path", "emqx.listeners", [
   {default, "/mqtt"},
   {datatype, string}
 ]}.
@@ -1365,7 +1375,8 @@ end}.
end,

LisOpts = fun(Prefix) ->
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
Filter([{standard_mqtt, cuttlefish:conf_get(Prefix ++ ".standard_mqtt", Conf, undefined)},

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
{mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
@@ -51,12 +51,12 @@ start_listener(Proto, ListenOn, Options) when Proto == ssl; Proto == tls ->

%% Start MQTT/WS listener
start_listener(Proto, ListenOn, Options) when Proto == http; Proto == ws ->
Dispatch = cowboy_router:compile([{'_', [{"/mqtt", emqx_ws_connection, Options}]}]),
Dispatch = cowboy_router:compile([{'_', [{subprotocol_name(Options), emqx_ws_connection, Options}]}]),

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
mqtt_path(Options)
start_http_listener(fun cowboy:start_clear/3, 'mqtt:ws', ListenOn, ranch_opts(Options), Dispatch);

%% Start MQTT/WSS listener
start_listener(Proto, ListenOn, Options) when Proto == https; Proto == wss ->
Dispatch = cowboy_router:compile([{'_', [{"/mqtt", emqx_ws_connection, Options}]}]),
Dispatch = cowboy_router:compile([{'_', [{subprotocol_name(Options), emqx_ws_connection, Options}]}]),

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

mqtt_path(Options)

true -> "/mqtt";
false -> "/"
end.

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
mqtt_path(Options) ->
    proplists:get_value(mqtt_path, Options, "/mqtt").
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};

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

Why put a default 'Message-Expiry-Interval'???

This comment has been minimized.

Copy link
@tigercl

tigercl Sep 14, 2018

Author Collaborator

Why put a default 'Message-Expiry-Interval'???

These code used in retainer plugin, I push it together with code of issue#1809 unexpectedly.

@@ -1207,6 +1207,11 @@ 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

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

The path of WebSocket MQTT endpoint

@@ -1346,6 +1351,11 @@ 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

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

The path of WebSocket MQTT endpoint

@@ -1365,7 +1375,8 @@ end}.
end,

LisOpts = fun(Prefix) ->
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
Filter([{mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
        {mqtt_path, cuttlefish:conf_get(Prefix ++ ".mqtt_path", Conf, undefined)},
-export([mqtt_path/1]).

-endif.

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor
-ifdef(TEST).
-compile(export_all).
-endif.
<<"/", _/binary>> -> MQTTPath;
_ -> "/mqtt"
end.

This comment has been minimized.

Copy link
@emqplus

emqplus Sep 14, 2018

Contributor

proplists:get_value(mqtt_path, Options, "/mqtt").

tigercl added 2 commits Sep 14, 2018
@emqplus emqplus merged commit f5ed6dd into emqx:emqx30 Sep 14, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls First build on emqx30 at 54.782%
Details
@emqplus emqplus added this to the 3.0-beta.3 milestone Sep 14, 2018
@emqplus emqplus added the Enhancement label Sep 14, 2018
@terry-xiaoyu terry-xiaoyu changed the title Add feature for issue#1809 Configurable websocket path Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.