Skip to content

Commit

Permalink
Merge pull request #79 from inaka/jfacorro.72.cowboy.2
Browse files Browse the repository at this point in the history
[Closes #72] Update to Cowboy 2
  • Loading branch information
elbrujohalcon authored Nov 29, 2017
2 parents 2b2ced0 + 83effb7 commit 89daea6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sudo: false
language: erlang
otp_release:
- 20.1
- 19.2
- 18.3
before_install:
- ./ci before_install "${PWD:?}"/rebar3
install:
Expand Down
5 changes: 2 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
{deps_dir, "deps"}.
{deps,
[
{cowboy, "1.0.4"},
{ranch, "1.2.1"}
{cowboy, "2.1.0"}
]
}.

Expand All @@ -22,7 +21,7 @@
{deps, [
{katana_test, {git, "https://github.com/inaka/katana-test", {ref, "0.0.5"}}},
{mixer, {git, "https://github.com/inaka/mixer", {ref, "0.1.5"}}},
{meck, "0.8.4"},
{meck, "0.8.6"},
{xref_runner, {git, "https://github.com/inaka/xref_runner", {ref, "0.2.6"}}}
]}
]}
Expand Down
6 changes: 3 additions & 3 deletions src/trails.erl
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ servers() ->

-spec host_matches(ranch:ref()) -> [route_match()].
host_matches(ServerRef) ->
Opts = lists:flatten(ets:match(ranch_server, {{opts, ServerRef}, '$1'})),
Env = proplists:get_value(env, Opts, []),
Dispatchs = proplists:get_value(dispatch, Env, []),
[Opts] = lists:flatten(ets:match(ranch_server, {{opts, ServerRef}, '$1'})),
Env = maps:get(env, Opts, #{}),
Dispatchs = maps:get(dispatch, Env, []),
lists:flatten([Host || {Host, _, _} <- Dispatchs]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
22 changes: 7 additions & 15 deletions test/trails_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,13 @@ server_hostmatches(_Config) ->
Routes2 = [{"hostmatch3", Trails3}],
Dispatch2 = trails:compile(Routes2),

ListenerCount = 10,

RanchOptions1 = [{port, 8080}],
CowboyOptions1 = make_cowboy_options(Dispatch1),
{ok, _} =
cowboy:start_http(server1, ListenerCount, RanchOptions1, CowboyOptions1),
{ok, _} = cowboy:start_clear(server1, RanchOptions1, CowboyOptions1),

RanchOptions2 = [{port, 8081}],
CowboyOptions2 = make_cowboy_options(Dispatch2),
{ok, _} =
cowboy:start_http(server2, ListenerCount, RanchOptions2, CowboyOptions2),
{ok, _} = cowboy:start_clear(server2, RanchOptions2, CowboyOptions2),

Servers = trails:servers(),
true = lists:member(server1, Servers) andalso lists:member(server2, Servers),
Expand Down Expand Up @@ -459,13 +455,9 @@ get_trails3() ->
].

%% @private
-spec make_cowboy_options(cowboy_router:dispatch_rules()) -> [tuple()].
-spec make_cowboy_options(cowboy_router:dispatch_rules()) -> map().
make_cowboy_options(Dispatch) ->
[
{env,
[
{dispatch, Dispatch}
]},
{compress, true},
{timeout, 12000}
].
#{ env => #{dispatch => Dispatch}
, compress => true
, timeout => 12000
}.
15 changes: 10 additions & 5 deletions test/trails_meta_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
-module(trails_meta_SUITE).

-include_lib("mixer/include/mixer.hrl").
-mixin([{ktn_meta_SUITE
, [ all/0
-mixin([ { ktn_meta_SUITE
, [ all/0
, xref/1
, dialyzer/1
, elvis/1
]
}]).
]
}]).

-export([init_per_suite/1]).
-export([ init_per_suite/1
, end_per_suite/1
]).

-type config() :: [{atom(), term()}].

-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
[ {application, trails} | Config].

-spec end_per_suite(config()) -> config().
end_per_suite(Config) -> Config.

0 comments on commit 89daea6

Please sign in to comment.