Fixed http publish API missing params
This commit is contained in:
parent
3074a4b0ab
commit
8d4ec32d1a
|
@ -88,13 +88,14 @@ handle_request(Method, Path, Req) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
http_publish(Req) ->
|
http_publish(Req) ->
|
||||||
Params = Req:recv_body(),
|
Params0 = mochiweb_request:parse_post(Req),
|
||||||
|
Params = [{iolist_to_binary(Key), Val} || {Key, Val} <- Params0],
|
||||||
lager:info("HTTP Publish: ~p", [Params]),
|
lager:info("HTTP Publish: ~p", [Params]),
|
||||||
Topics = topics(Params),
|
Topics = topics(Params),
|
||||||
ClientId = get_value("client", Params, http),
|
ClientId = get_value(<<"client">>, Params, http),
|
||||||
Qos = int(get_value("qos", Params, "0")),
|
Qos = int(get_value(<<"qos">>, Params, "0")),
|
||||||
Retain = bool(get_value("retain", Params, "0")),
|
Retain = bool(get_value(<<"retain">>, Params, "0")),
|
||||||
Payload = list_to_binary(get_value("message", Params)),
|
Payload = iolist_to_binary(get_value(<<"message">>, Params)),
|
||||||
case {validate(qos, Qos), validate(topics, Topics)} of
|
case {validate(qos, Qos), validate(topics, Topics)} of
|
||||||
{true, true} ->
|
{true, true} ->
|
||||||
lists:foreach(fun(Topic) ->
|
lists:foreach(fun(Topic) ->
|
||||||
|
@ -151,8 +152,11 @@ authorized(Req) ->
|
||||||
user_passwd(BasicAuth) ->
|
user_passwd(BasicAuth) ->
|
||||||
list_to_tuple(binary:split(base64:decode(BasicAuth), <<":">>)).
|
list_to_tuple(binary:split(base64:decode(BasicAuth), <<":">>)).
|
||||||
|
|
||||||
|
int(S) when is_integer(S)-> S;
|
||||||
int(S) -> list_to_integer(S).
|
int(S) -> list_to_integer(S).
|
||||||
|
|
||||||
|
bool(0) -> false;
|
||||||
|
bool(1) -> true;
|
||||||
bool("0") -> false;
|
bool("0") -> false;
|
||||||
bool("1") -> true.
|
bool("1") -> true.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue