Skip to content

Commit

Permalink
Merge pull request #264 from emqx/fix/qs
Browse files Browse the repository at this point in the history
fix(http): support query string parameter
  • Loading branch information
tigercl committed Jun 28, 2021
2 parents d52202c + 983c548 commit 9c4ac24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
24 changes: 4 additions & 20 deletions src/emqx_auth_http.appup.src
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
%% -*-: erlang -*-
{VSN,
[
{<<"4.2.([7-9]|(10)|(11)|(12))">>, [
{load_module, emqx_http_client, brutal_purge, soft_purge, []}
]},
{"4.2.6", [
{load_module, emqx_auth_http_cli, brutal_purge, soft_purge, []},
{load_module, emqx_http_client, brutal_purge, soft_purge, []}
]},
{<<"4.2.[0-5]">>, [
{<<".*">>, [
{restart_application, emqx_auth_http}
]},
{<<".*">>, []}
]}
],
[
{<<"4.2.([7-9]|(10)|(11)|(12))">>, [
{load_module, emqx_http_client, brutal_purge, soft_purge, []}
]},
{"4.2.6", [
{load_module, emqx_auth_http_cli, brutal_purge, soft_purge, []},
{load_module, emqx_http_client, brutal_purge, soft_purge, []}
]},
{<<"4.2.[0-5]">>, [
{<<".*">>, [
{restart_application, emqx_auth_http}
]},
{<<".*">>, []}
]}
]
}.
13 changes: 9 additions & 4 deletions src/emqx_auth_http_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ translate_env() ->
Env ->
URL = proplists:get_value(url, Env),
#{host := Host,
path := Path,
scheme := Scheme} = URIMap = uri_string:parse(add_default_scheme(URL)),
Port = maps:get(port, URIMap, case Scheme of
"https" -> 443;
_ -> 80
end),
[{Name, {Host, Port, path(Path)}} | Acc]
[{Name, {Host, Port, path(URIMap)}} | Acc]
end
end, [], [acl_req, auth_req, super_req]),
case same_host_and_port(URLs) of
Expand Down Expand Up @@ -163,8 +162,14 @@ add_default_scheme("https://" ++ _ = URL) ->
add_default_scheme(URL) ->
"http://" ++ URL.

path("") -> "/";
path(Path) -> Path.
path(#{path := "", 'query' := Query}) ->
"?" ++ Query;
path(#{path := Path, 'query' := Query}) ->
Path ++ "?" ++ Query;
path(#{path := ""}) ->
"/";
path(#{path := Path}) ->
Path.

same_host_and_port([_]) ->
true;
Expand Down

0 comments on commit 9c4ac24

Please sign in to comment.