Skip to content

Commit 7cb195e

Browse files
authored
Merge pull request #119 from paulo-ferraz-oliveira/feature/otp-22+_22-to-27
Update code for the new OTP 22-25 maintenance range
2 parents 3ec3522 + 9db9cc1 commit 7cb195e

File tree

6 files changed

+60
-108
lines changed

6 files changed

+60
-108
lines changed

.github/workflows/main.yml

+39-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,50 @@ jobs:
1414
runs-on: ${{ matrix.os }}
1515

1616
strategy:
17+
fail-fast: false
1718
matrix:
18-
otp_version: ['24', '23', '22', '21']
19-
os: [ubuntu-latest]
19+
include:
20+
- otp_version: 25
21+
os: ubuntu-22.04
22+
rebar3_version: 3.22
23+
- otp_version: 24
24+
os: ubuntu-22.04
25+
rebar3_version: 3.22
26+
- otp_version: 23
27+
os: ubuntu-20.04
28+
rebar3_version: 3.18
29+
- otp_version: 22
30+
os: ubuntu-20.04
31+
rebar3_version: 3.18
2032

2133
steps:
22-
- uses: actions/checkout@v2
34+
- uses: actions/checkout@v4
2335

2436
- uses: erlef/setup-beam@v1
37+
id: setup-beam
2538
with:
2639
otp-version: ${{ matrix.otp_version }}
27-
rebar3-version: '3.14'
40+
rebar3-version: ${{ matrix.rebar3_version }}
41+
42+
- name: Restore _build
43+
uses: actions/cache@v3
44+
with:
45+
path: _build
46+
key: "_build-cache-for\
47+
-os-${{ matrix.os }}\
48+
-otp-${{ steps.setup-beam.outputs.otp-version }}\
49+
-rebar3-${{ steps.setup-beam.outputs.rebar3-version }}\
50+
-hash-${{ hashFiles('rebar.lock') }}"
51+
52+
- name: Restore rebar3's cache
53+
uses: actions/cache@v3
54+
with:
55+
path: ~/.cache/rebar3
56+
key: "rebar3-cache-for\
57+
-os-${{ matrix.os }}\
58+
-otp-${{ steps.setup-beam.outputs.otp-version }}\
59+
-rebar3-${{ steps.setup-beam.outputs.rebar3-version }}\
60+
-hash-${{ hashFiles('rebar.lock') }}"
2861

2962
- name: Compile
3063
run: rebar3 compile
@@ -36,9 +69,8 @@ jobs:
3669
run: rebar3 xref
3770

3871
- name: Covertool
39-
if: ${{ always() }}
4072
run: rebar3 covertool generate
41-
- uses: codecov/codecov-action@v1
73+
- uses: codecov/codecov-action@v4
4274
with:
43-
file: _build/test/covertool/elli.covertool.xml
75+
files: _build/test/covertool/elli.covertool.xml
4476
env_vars: OTP_VERSION

rebar.config

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{erl_first_files, ["src/elli_handler.erl"]}.
22
{erl_opts, [debug_info,
3-
{i, "include"},
4-
{platform_define, "^2", binary_http_uri},
5-
{platform_define, "^2[1-9]", post20}]}.
6-
{minimum_otp_vsn, "20.0"}.
3+
{i, "include"}]}.
4+
{minimum_otp_vsn, "22.0"}.
75
{deps, []}.
86
{xref_checks, [undefined_function_calls,locals_not_used]}.
97
{profiles, [
@@ -25,11 +23,11 @@
2523
{shell, [{script_file, "bin/shell.escript"}]}.
2624

2725
{project_plugins, [
28-
{covertool, "2.0.3"},
29-
{rebar3_lint, "v0.1.10"}
26+
{covertool, "2.0.3"}%,
27+
%{rebar3_lint, "v0.1.10"}
3028
]}.
3129

32-
{provider_hooks, [{pre, [{eunit, lint}]}]}.
30+
%{provider_hooks, [{pre, [{eunit, lint}]}]}.
3331
{dialyzer, [{plt_extra_apps, [ssl]}]}.
3432

3533
{cover_enabled, true}.

src/elli_http.erl

+16-62
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,17 @@ execute_callback(#req{callback = {Mod, Args}} = Req) ->
323323
catch
324324
throw:{ResponseCode, Headers, Body} when is_integer(ResponseCode) ->
325325
{response, ResponseCode, Headers, Body};
326-
?WITH_STACKTRACE(throw, Exc, Stacktrace)
326+
throw:Exc:Stacktrace ->
327327
handle_event(Mod, request_throw,
328328
[Req, Exc, Stacktrace],
329329
Args),
330330
{response, 500, [], <<"Internal server error">>};
331-
?WITH_STACKTRACE(error, Error, Stacktrace)
331+
error:Error:Stacktrace ->
332332
handle_event(Mod, request_error,
333333
[Req, Error, Stacktrace],
334334
Args),
335335
{response, 500, [], <<"Internal server error">>};
336-
?WITH_STACKTRACE(exit, Exit, Stacktrace)
336+
exit:Exit:Stacktrace ->
337337
handle_event(Mod, request_exit,
338338
[Req, Exit, Stacktrace],
339339
Args),
@@ -708,7 +708,6 @@ is_header_defined(Key, Headers) ->
708708
get_header(Key, Headers) ->
709709
get_header(Key, Headers, undefined).
710710

711-
-ifdef(OTP_RELEASE).
712711
get_header(Key, Headers, Default) ->
713712
CaseFoldedKey = string:casefold(Key),
714713
case lists:search(fun({N, _}) -> string:equal(CaseFoldedKey, N, true) end, Headers) of
@@ -717,68 +716,23 @@ get_header(Key, Headers, Default) ->
717716
false ->
718717
Default
719718
end.
720-
-else.
721-
get_header(Key, Headers, Default) ->
722-
CaseFoldedKey = string:casefold(Key),
723-
case search(fun({N, _}) -> string:equal(CaseFoldedKey, N, true) end, Headers) of
724-
{value, {_, Value}} ->
725-
Value;
726-
false ->
727-
Default
728-
end.
729-
730-
search(Pred, [Hd|Tail]) ->
731-
case Pred(Hd) of
732-
true -> {value, Hd};
733-
false -> search(Pred, Tail)
734-
end;
735-
search(Pred, []) when is_function(Pred, 1) ->
736-
false.
737-
-endif.
738719

739720
%%
740721
%% PATH HELPERS
741722
%%
742723

743-
-ifdef(OTP_RELEASE).
744-
-if(?OTP_RELEASE >= 22).
745-
parse_path({abs_path, FullPath}) ->
746-
URIMap = uri_string:parse(FullPath),
747-
Host = maps:get(host, URIMap, undefined),
748-
Scheme = maps:get(scheme, URIMap, undefined),
749-
Path = maps:get(path, URIMap, <<>>),
750-
Query = maps:get(query, URIMap, <<>>),
751-
Port = maps:get(port, URIMap, case Scheme of http -> 80; https -> 443; _ -> undefined end),
752-
{ok, {Scheme, Host, Port}, {Path, split_path(Path), uri_string:dissect_query(Query)}};
753-
parse_path({absoluteURI, Scheme, Host, Port, Path}) ->
754-
setelement(2, parse_path({abs_path, Path}), {Scheme, Host, Port});
755-
parse_path(_) ->
756-
{error, unsupported_uri}.
757-
-else.
758-
parse_path({abs_path, FullPath}) ->
759-
Parsed = case binary:split(FullPath, [<<"?">>]) of
760-
[URL] -> {FullPath, split_path(URL), []};
761-
[URL, Args] -> {FullPath, split_path(URL), split_args(Args)}
762-
end,
763-
{ok, {undefined, undefined, undefined}, Parsed};
764-
parse_path({absoluteURI, Scheme, Host, Port, Path}) ->
765-
setelement(2, parse_path({abs_path, Path}), {Scheme, Host, Port});
766-
parse_path(_) ->
767-
{error, unsupported_uri}.
768-
-endif.
769-
-else.
770-
%% same as else branch above. can drop this when only OTP 21+ is supported
771-
parse_path({abs_path, FullPath}) ->
772-
Parsed = case binary:split(FullPath, [<<"?">>]) of
773-
[URL] -> {FullPath, split_path(URL), []};
774-
[URL, Args] -> {FullPath, split_path(URL), split_args(Args)}
775-
end,
776-
{ok, {undefined, undefined, undefined}, Parsed};
777-
parse_path({absoluteURI, Scheme, Host, Port, Path}) ->
778-
setelement(2, parse_path({abs_path, Path}), {Scheme, Host, Port});
779-
parse_path(_) ->
780-
{error, unsupported_uri}.
781-
-endif.
724+
parse_path({abs_path, FullPath}) ->
725+
URIMap = uri_string:parse(FullPath),
726+
Host = maps:get(host, URIMap, undefined),
727+
Scheme = maps:get(scheme, URIMap, undefined),
728+
Path = maps:get(path, URIMap, <<>>),
729+
Query = maps:get(query, URIMap, <<>>),
730+
Port = maps:get(port, URIMap, case Scheme of http -> 80; https -> 443; _ -> undefined end),
731+
{ok, {Scheme, Host, Port}, {Path, split_path(Path), uri_string:dissect_query(Query)}};
732+
parse_path({absoluteURI, Scheme, Host, Port, Path}) ->
733+
setelement(2, parse_path({abs_path, Path}), {Scheme, Host, Port});
734+
parse_path(_) ->
735+
{error, unsupported_uri}.
782736

783737
split_path(Path) ->
784738
[P || P <- binary:split(Path, [<<"/">>], [global]),
@@ -813,7 +767,7 @@ handle_event(Mod, Name, EventArgs, ElliArgs) ->
813767
try
814768
Mod:handle_event(Name, EventArgs, ElliArgs)
815769
catch
816-
?WITH_STACKTRACE(EvClass, EvError, Stacktrace)
770+
EvClass:EvError:Stacktrace ->
817771
?LOG_ERROR("~p:handle_event/3 crashed ~p:~p~n~p",
818772
[Mod, EvClass, EvError, Stacktrace])
819773
end.

src/elli_tcp.erl

-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ accept({ssl, Socket}, Server, Timeout) ->
4242
{error, Reason}
4343
end.
4444

45-
-ifdef(post20).
4645
handshake(S, Server, Timeout) ->
4746
case ssl:handshake(S, Timeout) of
4847
{ok, S1} ->
@@ -53,18 +52,6 @@ handshake(S, Server, Timeout) ->
5352
{error, Reason} ->
5453
{error, Reason}
5554
end.
56-
-else.
57-
handshake(S, Server, Timeout) ->
58-
case ssl:ssl_accept(S, Timeout) of
59-
ok ->
60-
gen_server:cast(Server, accepted),
61-
{ok, {ssl, S}};
62-
{error, closed} ->
63-
{error, econnaborted};
64-
{error, Reason} ->
65-
{error, Reason}
66-
end.
67-
-endif.
6855

6956
recv({plain, Socket}, Size, Timeout) ->
7057
gen_tcp:recv(Socket, Size, Timeout);

src/elli_util.hrl

-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
2-
-ifdef(OTP_RELEASE).
31
-include_lib("kernel/include/logger.hrl").
4-
-else.
5-
-define(LOG_ERROR(Str), error_logger:error_msg(Str)).
6-
-define(LOG_ERROR(Format,Data), error_logger:error_msg(Format, Data)).
7-
-define(LOG_INFO(Format,Data), error_logger:info_msg(Format, Data)).
8-
-endif.
9-
10-
-ifdef(OTP_RELEASE).
11-
-define(WITH_STACKTRACE(T, R, S), T:R:S ->).
12-
-else.
13-
-define(WITH_STACKTRACE(T, R, S), T:R -> S = erlang:get_stacktrace(),).
14-
-endif.
152

163
%% Bloody useful
174
-define(IF(Test,True,False), case Test of true -> True; false -> False end).

test/elli_tests.erl

-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
-define(VTB(T1, T2, LB, UB),
88
time_diff_to_micro_seconds(T1, T2) >= LB andalso
99
time_diff_to_micro_seconds(T1, T2) =< UB).
10-
-ifdef(OTP_RELEASE).
1110
-include_lib("kernel/include/logger.hrl").
12-
-else.
13-
-define(LOG_ERROR(Str), error_logger:error_msg(Str)).
14-
-define(LOG_ERROR(Format,Data), error_logger:error_msg(Format, Data)).
15-
-define(LOG_INFO(Format,Data), error_logger:info_msg(Format, Data)).
16-
-endif.
1711

1812
time_diff_to_micro_seconds(T1, T2) ->
1913
erlang:convert_time_unit(

0 commit comments

Comments
 (0)