Skip to content

Commit e081ef0

Browse files
committed
Set minimum OTP to 18
1 parent fce80ef commit e081ef0

File tree

12 files changed

+20
-110
lines changed

12 files changed

+20
-110
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ jobs:
1313
os:
1414
- ubuntu-latest
1515
otp:
16-
- "24.0.2"
17-
- "23.3.1"
18-
- "22.3.4.9"
19-
- "21.3.8.17"
16+
- "24.3.3"
17+
- "23.3.4.14"
18+
- "22.3.4.26"
19+
- "21.3.8.24"
2020
- "20.3.8.26"
2121
include:
22-
- os: ubuntu-18.04
23-
otp: "21.2.7"
2422
- os: ubuntu-18.04
2523
otp: "19.3.6.13"
2624
- os: ubuntu-18.04
2725
otp: "18.3.4.11"
28-
- os: ubuntu-18.04
29-
otp: "16.b.2.basho10"
3026
steps:
3127
- uses: actions/[email protected]
3228
- run: |

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

CHANGES.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
New version
1+
Version 3.0.0 released 2022-XX-XX
22

3+
* Minimum OTP version is now 18, which
4+
allows us to remove a number of backwards
5+
compatibility hacks while still supporting
6+
almost 7 years of Erlang releases.
7+
https://github.com/mochi/mochiweb/pull/239
38
* Crashing client processes now exit with reason
49
`{shutdown, Error}`. This ensures processes
510
linked to the connection process are also

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To create a new mochiweb using project in a specific directory:
1515
Information about Rebar (Erlang build tool) is available at https://github.com/rebar/rebar
1616

1717
MochiWeb is currently tested with Erlang/OTP 18.3 through 24.0,
18-
but may still be compatible back to R15B-03.
18+
versions older than 3.0.0 may still be compatible back to R15B-03.
1919

2020
# OTP 21.2, 21.2.1, 21.2.2 warning
2121

rebar.config

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
% -*- mode: erlang -*-
22
{erl_opts, [debug_info,
3-
{platform_define, "^R15", 'gen_tcp_r15b_workaround'},
4-
{platform_define, "^(R14|R15|R16B-)", 'crypto_compatibility'},
5-
{platform_define, "^(R14|R15|R16|17|18|19|20|21|22)", new_crypto_unavailable},
6-
{platform_define, "^(R14|R15|R16B|17)", 'rand_mod_unavailable'},
7-
{platform_define, "^(R14|R15|R16B|17)", 'sni_unavailable'},
8-
{platform_define, "^(R14|R15|R16)", 'map_unavailable'},
9-
{platform_define, "^(R14|R15|R16|17|18|19|20)", 'ssl_handshake_unavailable'},
10-
{platform_define, "^21-", 'otp_21'}]}.
3+
{platform_define, "^(18|19|20|21|22)", new_crypto_unavailable},
4+
{platform_define, "^(18|19|20)", ssl_handshake_unavailable},
5+
{platform_define, "^21-", otp_21}]}.
116
{cover_enabled, true}.
127
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
138
{dialyzer_opts, [{warnings, [no_return,

src/mochijson2.erl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@
8282
-define(IS_WHITESPACE(C),
8383
(C =:= $\s orelse C =:= $\t orelse C =:= $\r orelse C =:= $\n)).
8484

85-
-ifdef(map_unavailable).
86-
-define(IS_MAP(_), false).
87-
-else.
88-
-define(IS_MAP(X), is_map(X)).
89-
-endif.
9085

9186
%% @type json_string() = atom | binary()
9287
%% @type json_number() = integer() | float()
@@ -159,14 +154,8 @@ parse_decoder_options([{format, Format} | Rest], State)
159154
when Format =:= struct orelse Format =:= eep18 orelse Format =:= proplist ->
160155
parse_decoder_options(Rest, State#decoder{object_hook=Format}).
161156

162-
-ifdef(map_unavailable).
163-
make_object_hook_for_map() ->
164-
exit({json_decode, {bad_format, map_unavailable}}).
165-
-else.
166157
make_object_hook_for_map() ->
167158
fun ({struct, P}) -> maps:from_list(P) end.
168-
-endif.
169-
170159

171160
json_encode(true, _State) ->
172161
<<"true">>;
@@ -194,7 +183,7 @@ json_encode(Array, State) when is_list(Array) ->
194183
json_encode_array(Array, State);
195184
json_encode({array, Array}, State) when is_list(Array) ->
196185
json_encode_array(Array, State);
197-
json_encode(M, State) when ?IS_MAP(M) ->
186+
json_encode(M, State) when is_map(M) ->
198187
json_encode_map(M, State);
199188
json_encode({json, IoList}, _State) ->
200189
IoList;
@@ -223,11 +212,6 @@ json_encode_proplist(Props, State) ->
223212
[$, | Acc1] = lists:foldl(F, "{", Props),
224213
lists:reverse([$\} | Acc1]).
225214

226-
-ifdef(map_unavailable).
227-
json_encode_map(Bad, _State) ->
228-
%% IS_MAP definition guarantees that this branch is dead
229-
exit({json_encode, {bad_term, Bad}}).
230-
-else.
231215
json_encode_map(Map, _State) when map_size(Map) =:= 0 ->
232216
<<"{}">>;
233217
json_encode_map(Map, State) ->
@@ -238,7 +222,6 @@ json_encode_map(Map, State) ->
238222
end,
239223
[$, | Acc1] = maps:fold(F, "{", Map),
240224
lists:reverse([$\} | Acc1]).
241-
-endif.
242225

243226
json_encode_string(A, State) when is_atom(A) ->
244227
json_encode_string(atom_to_binary(A, latin1), State);
@@ -977,8 +960,6 @@ utf8_non_character_test_() ->
977960
[{"roundtrip escaped", ?_assertEqual(S, decode(encode(S)))},
978961
{"roundtrip utf8", ?_assertEqual(S, decode((encoder([{utf8, true}]))(S)))}].
979962

980-
-ifndef(map_unavailable).
981-
982963
decode_map_test() ->
983964
Json = "{\"var1\": 3, \"var2\": {\"var3\": 7}}",
984965
M = #{<<"var1">> => 3,<<"var2">> => #{<<"var3">> => 7}},
@@ -992,5 +973,3 @@ encode_empty_map_test() ->
992973
?assertEqual(<<"{}">>, encode(#{})).
993974

994975
-endif.
995-
996-
-endif.

src/mochiweb.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% This is generated from src/mochiweb.app.src
22
{application, mochiweb,
33
[{description, "MochiMedia Web Server"},
4-
{vsn, "2.22.0"},
4+
{vsn, "3.0.0"},
55
{modules, []},
66
{registered, []},
77
{env, []},

src/mochiweb_http.erl

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@
4343

4444
-define(DEFAULTS, [{name, ?MODULE}, {port, 8888}]).
4545

46-
-ifdef(gen_tcp_r15b_workaround).
47-
48-
r15b_workaround() -> false.
49-
50-
-else.
51-
52-
r15b_workaround() -> false.
53-
54-
-endif.
55-
5646
parse_options(Options) ->
5747
{loop, HttpLoop} = proplists:lookup(loop, Options),
5848
Loop = {?MODULE, loop, [HttpLoop]},
@@ -177,17 +167,10 @@ handle_invalid_msg_request(Msg, Socket, Opts) ->
177167
-spec handle_invalid_msg_request(term(), term(), term(),
178168
term(), term()) -> no_return().
179169

180-
handle_invalid_msg_request(Msg, Socket, Opts, Request,
170+
handle_invalid_msg_request(_Msg, Socket, Opts, Request,
181171
RevHeaders) ->
182-
case {Msg, r15b_workaround()} of
183-
{{tcp_error, _, emsgsize}, true} ->
184-
%% R15B02 returns this then closes the socket, so close and exit
185-
mochiweb_socket:close(Socket),
186-
exit({shutdown, {tcp_error, emsgsize}});
187-
_ ->
188-
handle_invalid_request(Socket, Opts, Request,
189-
RevHeaders)
190-
end.
172+
handle_invalid_request(Socket, Opts, Request,
173+
RevHeaders).
191174

192175
-spec handle_invalid_request(term(), term(), term(),
193176
term()) -> no_return().

src/mochiweb_session.erl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,6 @@ ensure_binary(B) when is_binary(B) ->
119119
ensure_binary(L) when is_list(L) ->
120120
iolist_to_binary(L).
121121

122-
-ifdef(crypto_compatibility).
123-
-spec encrypt_data(binary(), binary()) -> binary().
124-
encrypt_data(Data, Key) ->
125-
IV = crypto:strong_rand_bytes(16),
126-
Crypt = crypto:aes_cfb_128_encrypt(Key, IV, Data),
127-
<<IV/binary, Crypt/binary>>.
128-
129-
-spec decrypt_data(binary(), binary()) -> binary().
130-
decrypt_data(<<IV:16/binary, Crypt/binary>>, Key) ->
131-
crypto:aes_cfb_128_decrypt(Key, IV, Crypt).
132-
133-
-spec gen_key(iolist(), iolist()) -> binary().
134-
gen_key(ExpirationTime, ServerKey) ->
135-
crypto:md5_mac(ServerKey, [ExpirationTime]).
136-
137-
-spec gen_hmac(iolist(), binary(), iolist(), binary()) -> binary().
138-
gen_hmac(ExpirationTime, Data, SessionKey, Key) ->
139-
crypto:sha_mac(Key, [ExpirationTime, Data, SessionKey]).
140-
141-
-else.
142122
-ifdef(new_crypto_unavailable).
143123
-spec encrypt_data(binary(), binary()) -> binary().
144124
encrypt_data(Data, Key) ->
@@ -178,7 +158,6 @@ gen_hmac(ExpirationTime, Data, SessionKey, Key) ->
178158
crypto:mac(hmac, sha, Key, [ExpirationTime, Data, SessionKey]).
179159

180160
-endif.
181-
-endif.
182161

183162
-ifdef(TEST).
184163
-include_lib("eunit/include/eunit.hrl").

src/mochiweb_util.erl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,8 @@ normalize_path("/" ++ Path, "/" ++ _ = Acc) ->
627627
normalize_path([C|Path], Acc) ->
628628
normalize_path(Path, [C|Acc]).
629629

630-
-ifdef(rand_mod_unavailable).
631-
rand_uniform(Start, End) ->
632-
crypto:rand_uniform(Start, End).
633-
-else.
634630
rand_uniform(Start, End) ->
635631
Start + rand:uniform(End - Start) - 1.
636-
-endif.
637632

638633
%%
639634
%% Tests

0 commit comments

Comments
 (0)