Skip to content

Commit

Permalink
Merge pull request #3618 from esl/fix-cowboy-static-config
Browse files Browse the repository at this point in the history
Fix cowboy_static options
  • Loading branch information
Premwoik authored Apr 1, 2022
2 parents 7cbb30d + 44d398c commit 237ecb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ http_handler(Key) ->
ExtraItems = http_handler_items(Key),
RequiredKeys = case http_handler_required(Key) of
all -> all;
[] -> [<<"host">>, <<"path">>]
Keys -> Keys ++ [<<"host">>, <<"path">>]
end,
#section{
items = ExtraItems#{<<"host">> => #option{type = string,
Expand Down Expand Up @@ -474,7 +474,7 @@ http_handler_items(_) ->
#{}.

http_handler_required(<<"lasse_handler">>) -> all;
http_handler_required(<<"cowboy_static">>) -> all;
http_handler_required(<<"cowboy_static">>) -> [<<"type">>, <<"content_path">>];
http_handler_required(<<"mongoose_api">>) -> all;
http_handler_required(_) -> [].

Expand Down Expand Up @@ -1151,9 +1151,12 @@ process_http_handler([item, Type | _], KVs) ->
process_http_handler_opts(<<"lasse_handler">>, [{module, Module}]) ->
[Module];
process_http_handler_opts(<<"cowboy_static">>, Opts) ->
{[[{type, Type}], [{app, App}], [{content_path, Path}]], []} =
proplists:split(Opts, [type, app, content_path]),
{Type, App, Path, [{mimetypes, cow_mimetypes, all}]};
case proplists:split(Opts, [type, app, content_path]) of
{[[{type, Type}], [{app, App}], [{content_path, Path}]], []} ->
{Type, App, Path, [{mimetypes, cow_mimetypes, all}]};
{[[{type, Type}], [], [{content_path, Path}]], []} ->
{Type, Path, [{mimetypes, cow_mimetypes, all}]}
end;
process_http_handler_opts(<<"mongoose_api_admin">>, Opts) ->
{[UserOpts, PassOpts], []} = proplists:split(Opts, [username, password]),
case {UserOpts, PassOpts} of
Expand Down
5 changes: 5 additions & 0 deletions test/config_parser_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,11 @@ listen_http_handlers_static(_Config) ->
http_handler_raw(<<"cowboy_static">>, #{<<"type">> => <<"priv_dir">>,
<<"app">> => <<"cowboy_swagger">>,
<<"content_path">> => <<"swagger">>})),
?cfg(listener_config(ejabberd_cowboy, #{modules => [{"localhost", "/api", cowboy_static,
{file, "swagger", [{mimetypes, cow_mimetypes, all}]}
}]}),
http_handler_raw(<<"cowboy_static">>, #{<<"type">> => <<"file">>,
<<"content_path">> => <<"swagger">>})),
?err(http_handler_raw(<<"cowboy_static">>, #{<<"type">> => <<"priv_dir">>,
<<"app">> => <<"cowboy_swagger">>})).

Expand Down

0 comments on commit 237ecb2

Please sign in to comment.